[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master a1f603f 2/3: Add overflow check for INPUT_EVENT_POS_MIN
From: |
Paul Eggert |
Subject: |
master a1f603f 2/3: Add overflow check for INPUT_EVENT_POS_MIN |
Date: |
Fri, 1 Jan 2021 15:58:25 -0500 (EST) |
branch: master
commit a1f603f0a388a519771ef77ae18f44a448a81c5a
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>
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.
---
src/keyboard.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/keyboard.c b/src/keyboard.c
index 0cf7ada..d2f0cb4 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -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. */