summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2026-05-21 09:18:15 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2026-05-23 19:18:53 -0700
commitced12fa1140879d92a66475cf2a167e699e8e1c0 (patch)
treee9bb97fe7cf06dafb753788422f1845ed7e65c6a /src
parent42a8e12088b4ce08262ed158b56d60fa00e8c654 (diff)
Avoid memsets in charset.c
* src/charset.c (load_charset_map_from_file) (load_charset_map_from_vector, Fdefine_charset_internal): Rewrite memset to xzalloc or initializers.
Diffstat (limited to 'src')
-rw-r--r--src/charset.c34
1 files changed, 13 insertions, 21 deletions
diff --git a/src/charset.c b/src/charset.c
index b86304024fe..971dafc2b9d 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -496,11 +496,9 @@ load_charset_map_from_file (struct charset *charset, Lisp_Object mapfile,
set_unwind_protect_ptr (count, fclose_unwind, fp);
unbind_to (specpdl_ref_add (count, 1), Qnil);
- /* Use record_xmalloc, as `charset_map_entries' is
- large (larger than MAX_ALLOCA). */
- head = record_xmalloc (sizeof *head);
- entries = head;
- memset (entries, 0, sizeof (struct charset_map_entries));
+ /* charset_map_entries is large, so don't SAFE_ALLOCA. */
+ entries = head = xzalloc (sizeof *head);
+ record_unwind_protect_ptr (xfree, entries);
n_entries = 0;
int ch = -1;
@@ -532,9 +530,8 @@ load_charset_map_from_file (struct charset *charset, Lisp_Object mapfile,
if (n_entries == 0x10000)
{
- entries->next = record_xmalloc (sizeof *entries->next);
- entries = entries->next;
- memset (entries, 0, sizeof (struct charset_map_entries));
+ entries = entries->next = xzalloc (sizeof *entries->next);
+ record_unwind_protect_ptr (xfree, entries);
n_entries = 0;
}
int idx = n_entries;
@@ -559,7 +556,7 @@ load_charset_map_from_vector (struct charset *charset, Lisp_Object vec, int cont
int n_entries;
int len = ASIZE (vec);
int i;
- USE_SAFE_ALLOCA;
+ specpdl_ref count = SPECPDL_INDEX ();
if (len % 2 == 1)
{
@@ -567,11 +564,9 @@ load_charset_map_from_vector (struct charset *charset, Lisp_Object vec, int cont
return;
}
- /* Use SAFE_ALLOCA instead of alloca, as `charset_map_entries' is
- large (larger than MAX_ALLOCA). */
- head = SAFE_ALLOCA (sizeof *head);
- entries = head;
- memset (entries, 0, sizeof (struct charset_map_entries));
+ /* charset_map_entries is large, so don't SAFE_ALLOCA. */
+ entries = head = xzalloc (sizeof *head);
+ record_unwind_protect_ptr (xfree, entries);
n_entries = 0;
for (i = 0; i < len; i += 2)
@@ -600,9 +595,8 @@ load_charset_map_from_vector (struct charset *charset, Lisp_Object vec, int cont
if (n_entries > 0 && (n_entries % 0x10000) == 0)
{
- entries->next = SAFE_ALLOCA (sizeof *entries->next);
- entries = entries->next;
- memset (entries, 0, sizeof (struct charset_map_entries));
+ entries = entries->next = xzalloc (sizeof *entries->next);
+ record_unwind_protect_ptr (xfree, entries);
}
idx = n_entries % 0x10000;
entries->entry[idx].from = from;
@@ -612,7 +606,7 @@ load_charset_map_from_vector (struct charset *charset, Lisp_Object vec, int cont
}
load_charset_map (charset, head, n_entries, control_flag);
- SAFE_FREE ();
+ unbind_to (count, Qnil);
}
@@ -852,14 +846,12 @@ usage: (define-charset-internal ...) */)
Lisp_Object val;
struct Lisp_Hash_Table *hash_table = XHASH_TABLE (Vcharset_hash_table);
int i, j;
- struct charset charset;
+ struct charset charset = {0};
int id;
int dimension;
bool new_definition_p;
int nchars;
- memset (&charset, 0, sizeof (charset));
-
if (nargs != charset_arg_max)
Fsignal (Qwrong_number_of_arguments,
Fcons (Qdefine_charset_internal,