]> code.delx.au - gnu-emacs/commitdiff
* coding.c (ALLOC_CONVERSION_WORK_AREA): Prefer ptrdiff_t to int and
authorDmitry Antipov <dmantipov@yandex.ru>
Wed, 9 Jul 2014 10:36:35 +0000 (14:36 +0400)
committerDmitry Antipov <dmantipov@yandex.ru>
Wed, 9 Jul 2014 10:36:35 +0000 (14:36 +0400)
so avoid integer overflow if decoded gap size exceeds INT_MAX bytes.

src/ChangeLog
src/coding.c

index 10984d5ce25189f69b5e39260eb9db242108bee8..fa79ac43bdf4970e5a7582ed8e83340e05b340ca 100644 (file)
@@ -15,6 +15,9 @@
        * xfont.c (xfont_open):
        * xftfont.c (xftfont_open): All users changed.
 
+       * coding.c (ALLOC_CONVERSION_WORK_AREA): Prefer ptrdiff_t to int and
+       so avoid integer overflow if decoded gap size exceeds INT_MAX bytes.
+
 2014-07-09  Eli Zaretskii  <eliz@gnu.org>
 
        * xdisp.c (move_it_to): Adjust calculation of line_start_x to what
index d4c468cfbbf8a790c10a83b1cd55400fcb55bd6c..5e7a676aecd06ba7048ee269d43829d9dcaa7785 100644 (file)
@@ -7273,15 +7273,12 @@ produce_charset (struct coding_system *coding, int *charbuf, ptrdiff_t pos)
 
 #define ALLOC_CONVERSION_WORK_AREA(coding, size)               \
   do {                                                         \
-    int units = (size) + MAX_CHARBUF_EXTRA_SIZE;               \
-                                                               \
-    if (units > MAX_CHARBUF_SIZE)                              \
-      units = MAX_CHARBUF_SIZE;                                        \
-    coding->charbuf = SAFE_ALLOCA ((units) * sizeof (int));    \
-    coding->charbuf_size = (units);                            \
+    ptrdiff_t units = min ((size) + MAX_CHARBUF_EXTRA_SIZE,    \
+                          MAX_CHARBUF_SIZE);                   \
+    coding->charbuf = SAFE_ALLOCA (units * sizeof (int));      \
+    coding->charbuf_size = units;                              \
   } while (0)
 
-
 static void
 produce_annotation (struct coding_system *coding, ptrdiff_t pos)
 {