This is the mail archive of the
gdb-patches@sourceware.cygnus.com
mailing list for the GDB project.
[PATCH] Comparing tv_sec in event-loop.c
- To: gdb-patches at sourceware dot cygnus dot com
- Subject: [PATCH] Comparing tv_sec in event-loop.c
- From: Eli Zaretskii <eliz at delorie dot com>
- Date: Sun, 5 Mar 2000 03:41:54 -0500 (EST)
- CC: ezannoni at cygnus dot com
While working on the select-related changes, I've found a case of
mixing signed and unsigned which could really bite someone. (In
DJGPP, time_t is unsigned, so the compiler complained.)
Here's the patch:
2000-03-04 Eli Zaretskii <eliz@is.elta.co.il>
* event-loop.c (poll_timers): Don't compare delta.tv_sec with
zero, since time_t might be unsigned.
--- gdb/event-loop.c~0 Mon Feb 21 18:17:16 2000
+++ gdb/event-loop.c Sat Mar 4 14:38:28 2000
@@ -1114,8 +1105,11 @@ poll_timers (void)
}
/* Oops it expired already. Tell select / poll to return
- immediately. */
- if (delta.tv_sec < 0)
+ immediately. (Cannot simply test if delta.tv_sec is negative
+ because time_t might be unsigned.) */
+ if (timer_list.first_timer->when.tv_sec < time_now.tv_sec
+ || (timer_list.first_timer->when.tv_sec == time_now.tv_sec
+ && timer_list.first_timer->when.tv_usec < time_now.tv_usec))
{
delta.tv_sec = 0;
delta.tv_usec = 0;