From 2df762ce73a8fb9e58d67216e42abe90ee895629 Mon Sep 17 00:00:00 2001 From: Peter McCurdy Date: Tue, 3 Mar 2015 20:52:36 +0100 Subject: [PATCH] Make all time values signed longs instead of a mix of signed and unsigned, to avoid compiler complaints. check_timeout() tries to use some unsigned long variables to perform some intermediate calculations, then has to cast back to signed long. As it happens, there's no real chance of overflowing a signed long (it'll only happen if the current time is within 49.7 days of rolling over, at which point you're already pretty doomed), so we can make the calculations a bit simpler, and also avoid the mixed-signedness arithmetic we'd otherwise need to do. Bug: https://bugs.freedesktop.org/attachment.cgi?id=18494 --- dbus/dbus-mainloop.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/dbus/dbus-mainloop.c b/dbus/dbus-mainloop.c index 7ff9dc2..2501967 100644 --- a/dbus/dbus-mainloop.c +++ b/dbus/dbus-mainloop.c @@ -54,8 +54,8 @@ struct DBusLoop typedef struct { DBusTimeout *timeout; - unsigned long last_tv_sec; - unsigned long last_tv_usec; + long last_tv_sec; + long last_tv_usec; } TimeoutCallback; #define TIMEOUT_CALLBACK(callback) ((TimeoutCallback*)callback) @@ -421,15 +421,15 @@ _dbus_loop_remove_timeout (DBusLoop *loop, * to do this. */ static dbus_bool_t -check_timeout (unsigned long tv_sec, - unsigned long tv_usec, +check_timeout (long tv_sec, + long tv_usec, TimeoutCallback *tcb, int *timeout) { long sec_remaining; long msec_remaining; - unsigned long expiration_tv_sec; - unsigned long expiration_tv_usec; + long expiration_tv_sec; + long expiration_tv_usec; long interval_seconds; long interval_milliseconds; int interval; @@ -450,10 +450,7 @@ check_timeout (unsigned long tv_sec, } sec_remaining = expiration_tv_sec - tv_sec; - /* need to force this to be signed, as it is intended to sometimes - * produce a negative result - */ - msec_remaining = ((long) expiration_tv_usec - (long) tv_usec) / 1000L; + msec_remaining = (expiration_tv_usec - tv_usec) / 1000L; #if MAINLOOP_SPEW _dbus_verbose ("Interval is %ld seconds %ld msecs\n", @@ -595,8 +592,8 @@ _dbus_loop_iterate (DBusLoop *loop, timeout = -1; if (loop->timeout_count > 0) { - unsigned long tv_sec; - unsigned long tv_usec; + long tv_sec; + long tv_usec; _dbus_get_monotonic_time (&tv_sec, &tv_usec); @@ -704,8 +701,8 @@ _dbus_loop_iterate (DBusLoop *loop, if (loop->timeout_count > 0) { - unsigned long tv_sec; - unsigned long tv_usec; + long tv_sec; + long tv_usec; _dbus_get_monotonic_time (&tv_sec, &tv_usec); -- 1.8.4.5