From f1dd807386718d2c7c29d13b9f7615759086a954 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 23 Jun 2012 21:11:19 -0700 Subject: [PATCH] Fix bug when time_t is unsigned and as wide as intmax_t. * lisp.h (WAIT_READING_MAX): New macro. * dispnew.c (Fsleep_for, sit_for): * keyboard.c (kbd_buffer_get_event): * process.c (Faccept_process_output): Use it to avoid bogus compiler warnings with obsolescent GCC versions. This improves on the previous patch, which introduced a bug when time_t is unsigned and as wide as intmax_t. See . --- src/ChangeLog | 12 ++++++++++++ src/dispnew.c | 7 ++----- src/keyboard.c | 6 ++---- src/lisp.h | 8 ++++++++ src/process.c | 4 +--- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 40073d32834..a302db4fae6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2012-06-24 Paul Eggert + + Fix bug when time_t is unsigned and as wide as intmax_t (Bug#9000). + * lisp.h (WAIT_READING_MAX): New macro. + * dispnew.c (Fsleep_for, sit_for): + * keyboard.c (kbd_buffer_get_event): + * process.c (Faccept_process_output): + Use it to avoid bogus compiler warnings with obsolescent GCC versions. + This improves on the previous patch, which introduced a bug + when time_t is unsigned and as wide as intmax_t. + See . + 2012-06-23 Eli Zaretskii * dispnew.c (sit_for, Fsleep_for): diff --git a/src/dispnew.c b/src/dispnew.c index e18fca6f122..05c22be79ae 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -5957,9 +5957,7 @@ additional wait period, in milliseconds; this is for backwards compatibility. if (0 < duration) { EMACS_TIME t = EMACS_TIME_FROM_DOUBLE (duration); - intmax_t secs = EMACS_SECS (t); - - wait_reading_process_output (min (secs, INTMAX_MAX), + wait_reading_process_output (min (EMACS_SECS (t), WAIT_READING_MAX), EMACS_NSECS (t), 0, 0, Qnil, NULL, 0); } @@ -6007,8 +6005,7 @@ sit_for (Lisp_Object timeout, int reading, int do_display) else { EMACS_TIME t = EMACS_TIME_FROM_DOUBLE (seconds); - sec = EMACS_SECS (t); - sec = min (sec, INTMAX_MAX); + sec = min (EMACS_SECS (t), WAIT_READING_MAX); nsec = EMACS_NSECS (t); } } diff --git a/src/keyboard.c b/src/keyboard.c index 38b05c22063..a39be2b859c 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -3857,11 +3857,9 @@ kbd_buffer_get_event (KBOARD **kbp, return Qnil; /* finished waiting */ else { - intmax_t secs; - EMACS_SUB_TIME (duration, *end_time, duration); - secs = EMACS_SECS (duration); - wait_reading_process_output (min (secs, INTMAX_MAX), + wait_reading_process_output (min (EMACS_SECS (duration), + WAIT_READING_MAX), EMACS_NSECS (duration), -1, 1, Qnil, NULL, 0); } diff --git a/src/lisp.h b/src/lisp.h index dd8cdd348b2..275761b0e94 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3249,6 +3249,14 @@ extern int wait_reading_process_output (intmax_t, int, int, int, Lisp_Object, struct Lisp_Process *, int); +/* Max value for the first argument of wait_reading_process_output. */ +#if __GNUC__ == 3 || (__GNUC__ == 4 && __GNUC_MINOR__ <= 5) +/* Work around a bug in GCC 3.4.2, known to be fixed in GCC 4.6.3. + The bug merely causes a bogus warning, but the warning is annoying. */ +# define WAIT_READING_MAX min (TYPE_MAXIMUM (time_t), INTMAX_MAX) +#else +# define WAIT_READING_MAX INTMAX_MAX +#endif extern void add_keyboard_wait_descriptor (int); extern void delete_keyboard_wait_descriptor (int); #ifdef HAVE_GPM diff --git a/src/process.c b/src/process.c index b41a77f58fd..457a1a9c7ea 100644 --- a/src/process.c +++ b/src/process.c @@ -3996,9 +3996,7 @@ Return non-nil if we received any output before the timeout expired. */) if (0 < XFLOAT_DATA (seconds)) { EMACS_TIME t = EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (seconds)); - - secs = EMACS_SECS (t); - secs = min (secs, INTMAX_MAX); + secs = min (EMACS_SECS (t), WAIT_READING_MAX); nsecs = EMACS_NSECS (t); } } -- 2.39.2