From b9e20e39953ad27c720e265311fa71bd7c6c749e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 17 May 2026 22:17:47 -0700 Subject: [PATCH] Avoid malloc/free pairs in emit_static_object * src/comp.c (emit_static_object): Avoid an malloc/free of a 1 KiB buffer; just put it on the stack. Use strnlen+mempcpy instead of strncpy as there is no need to zero-fill buff. Use int for values that must fit in int since we are passing them to gcc_jit_context_new_rvalue_from_int. --- src/comp.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/comp.c b/src/comp.c index 0ac980e6276..c70b37bfdac 100644 --- a/src/comp.c +++ b/src/comp.c @@ -2783,16 +2783,17 @@ emit_static_object (const char *name, Lisp_Object obj) . Adjust if possible to reduce the number of function calls. */ - size_t chunk_size = NILP (Fcomp_libgccjit_version ()) ? 200 : 1024; - char *buff = xmalloc (chunk_size); + char buff[1024]; + int chunk_size = NILP (Fcomp_libgccjit_version ()) ? 200 : sizeof buff; for (ptrdiff_t i = 0; i < len;) { - strncpy (buff, p, chunk_size); - buff[chunk_size - 1] = 0; - uintptr_t l = strlen (buff); + int l = strnlen (p, chunk_size - 1); if (l != 0) { + char *buff_end = mempcpy (buff, p, l); + *buff_end = '\0'; + p += l; i += l; @@ -2836,7 +2837,6 @@ emit_static_object (const char *name, Lisp_Object obj) NULL)); } } - xfree (buff); gcc_jit_block_add_assignment ( block,