]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix bug in recent allocate_string_data patch
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 4 Jan 2020 21:33:44 +0000 (13:33 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 4 Jan 2020 21:34:06 +0000 (13:34 -0800)
Reported by Glenn Morris in:
https://lists.gnu.org/r/emacs-devel/2020-01/msg00098.html
* src/alloc.c (allocate_string_data): If the string is small and
there is not enough room in the current block, clear the string if
CLEARIT.

src/alloc.c

index d6d456a8fc0f2a0d57030465da7685cf9d3e2dd3..7eb37bb12da9fc8fcb0617bc72e6a00f32ed43c4 100644 (file)
@@ -1831,26 +1831,27 @@ allocate_string_data (struct Lisp_String *s,
       b->next_free = data;
       large_sblocks = b;
     }
-  else if (current_sblock == NULL
-          || (((char *) current_sblock + SBLOCK_SIZE
-               - (char *) current_sblock->next_free)
-              < (needed + GC_STRING_EXTRA)))
-    {
-      /* Not enough room in the current sblock.  */
-      b = lisp_malloc (SBLOCK_SIZE, false, MEM_TYPE_NON_LISP);
-      data = b->data;
-      b->next = NULL;
-      b->next_free = data;
-
-      if (current_sblock)
-       current_sblock->next = b;
-      else
-       oldest_sblock = b;
-      current_sblock = b;
-    }
   else
     {
       b = current_sblock;
+
+      if (b == NULL
+         || (SBLOCK_SIZE - GC_STRING_EXTRA
+             < (char *) b->next_free - (char *) b + needed))
+       {
+         /* Not enough room in the current sblock.  */
+         b = lisp_malloc (SBLOCK_SIZE, false, MEM_TYPE_NON_LISP);
+         data = b->data;
+         b->next = NULL;
+         b->next_free = data;
+
+         if (current_sblock)
+           current_sblock->next = b;
+         else
+           oldest_sblock = b;
+         current_sblock = b;
+       }
+
       data = b->next_free;
       if (clearit)
        memset (SDATA_DATA (data), 0, nbytes);