mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-01-07 01:50:18 +01:00
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 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
This commit is contained in:
parent
dca6591fa2
commit
c701117672
1 changed files with 11 additions and 14 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue