]> git.eshelyaron.com Git - emacs.git/commitdiff
Add overflow check for INPUT_EVENT_POS_MIN
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 1 Jan 2021 20:55:35 +0000 (12:55 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 1 Jan 2021 20:58:17 +0000 (12:58 -0800)
* src/keyboard.c (INPUT_EVENT_POS_MIN): Don’t assume (-1 -
INPUT_EVENT_POS_MAX) fits into ptrdiff_t.  This fixes a
purely-theoretical problem that cannot occur on two’s-complement
arithmetic.  The Solaris 10 compiler still complains incorrectly,
but oh well.

src/keyboard.c

index 0cf7adae741d1a84abb05032d1442516526cba2c..d2f0cb405f0ba50acbf733be89609fa633a30e6f 100644 (file)
@@ -3647,7 +3647,8 @@ kbd_buffer_unget_event (struct selection_input_event *event)
 #define INPUT_EVENT_POS_MAX \
   ((ptrdiff_t) min (PTRDIFF_MAX, min (TYPE_MAXIMUM (Time) / 2, \
                                      MOST_POSITIVE_FIXNUM)))
-#define INPUT_EVENT_POS_MIN (-1 - INPUT_EVENT_POS_MAX)
+#define INPUT_EVENT_POS_MIN (PTRDIFF_MIN < -INPUT_EVENT_POS_MAX \
+                            ? -1 - INPUT_EVENT_POS_MAX : PTRDIFF_MIN)
 
 /* Return a Time that encodes position POS.  POS must be in range.  */