* buffer.c (record_overlay_string): Check for size-calculation overflow.
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 17 Jun 2011 08:10:34 +0000 (01:10 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 17 Jun 2011 08:10:34 +0000 (01:10 -0700)
(struct sortstrlist.size, struct sortlist.used): Don't truncate size to int.

src/ChangeLog
src/buffer.c

index fcb6f66..a82ba93 100644 (file)
@@ -3,7 +3,10 @@
        * buffer.c (struct sortvec.priority, struct sortstr.priority):
        Now EMACS_INT, not int.
        (compare_overlays, cmp_for_strings): Avoid subtraction overflow.
-       (struct sortstr.size, record_overlay_string): Don't truncate size to int.
+       (struct sortstr.size, record_overlay_string)
+       (struct sortstrlist.size, struct sortlist.used):
+       Don't truncate size to int.
+       (record_overlay_string): Check for size-calculation overflow.
 
 2011-06-16  Paul Eggert  <eggert@cs.ucla.edu>
 
index 90a10ec..93f739c 100644 (file)
@@ -2933,8 +2933,8 @@ struct sortstr
 struct sortstrlist
 {
   struct sortstr *buf; /* An array that expands as needed; never freed.  */
-  int size;            /* Allocated length of that array.  */
-  int used;            /* How much of the array is currently in use.  */
+  ptrdiff_t size;      /* Allocated length of that array.  */
+  ptrdiff_t used;      /* How much of the array is currently in use.  */
   EMACS_INT bytes;             /* Total length of the strings in buf.  */
 };
 
@@ -2969,7 +2969,10 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str,
 
   if (ssl->used == ssl->size)
     {
-      if (ssl->buf)
+      if (min (PTRDIFF_MAX, SIZE_MAX) / (sizeof (struct sortstr) * 2)
+         < ssl->size)
+       memory_full (SIZE_MAX);
+      else if (0 < ssl->size)
        ssl->size *= 2;
       else
        ssl->size = 5;