Add overflow check for INPUT_EVENT_POS_MIN

* 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.
This commit is contained in:
Paul Eggert 2021-01-01 12:55:35 -08:00
parent 9076a631fe
commit a1f603f0a3

View 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. */