summaryrefslogtreecommitdiff
path: root/src/fns.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2026-05-17 22:49:44 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2026-05-18 23:10:42 -0700
commit07fe0b297bc7b9c4e344eedd8244a73edda95c77 (patch)
treea444012254289167cc0ea12e3ca5654876dd8fa2 /src/fns.c
parent7587bb2654a6c22f8c9709cefd3ad8d45938b199 (diff)
Fix undefined behavior in maybe_resize_hash_table
Problem discovered with GCC 16.1.1 -fsanitize=undefined. * src/fns.c (maybe_resize_hash_table): Avoid undefined behavior when h->key_and_value or h->hash are null pointers, in which case we call memcpy (destination, NULL, 0) which has undefined behavior in C89 through C23.
Diffstat (limited to 'src/fns.c')
-rw-r--r--src/fns.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/fns.c b/src/fns.c
index 1158f100ea0..a2312ffa1b9 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -4975,13 +4975,15 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h)
Lisp_Object *key_and_value
= hash_table_alloc_bytes (2 * new_size * sizeof *key_and_value);
- memcpy (key_and_value, h->key_and_value,
- 2 * old_size * sizeof *key_and_value);
+ if (old_size)
+ memcpy (key_and_value, h->key_and_value,
+ 2 * old_size * sizeof *key_and_value);
for (ptrdiff_t i = 2 * old_size; i < 2 * new_size; i++)
key_and_value[i] = HASH_UNUSED_ENTRY_KEY;
hash_hash_t *hash = hash_table_alloc_bytes (new_size * sizeof *hash);
- memcpy (hash, h->hash, old_size * sizeof *hash);
+ if (old_size)
+ memcpy (hash, h->hash, old_size * sizeof *hash);
ptrdiff_t old_index_size = hash_table_index_size (h);
ptrdiff_t index_bits = compute_hash_index_bits (new_size);