mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
tests: Fix overflows in find_maximum_supported_tv_sec()
The addition (highest_success + lowest_failure) could have overflowed, and typically would do on 32-bit platforms where the real highest_success should be G_MAXLONG. Fix that, and introduce special handling of the corner case of (highest_success = G_MAXLONG). Signed-off-by: Philip Withnall <withnall@endlessm.com> https://bugzilla.gnome.org/show_bug.cgi?id=783841
This commit is contained in:
parent
30fed3b906
commit
428acd9b14
@ -370,19 +370,27 @@ test_GDateTime_new_from_timeval (void)
|
||||
g_date_time_unref (dt);
|
||||
}
|
||||
|
||||
static gint64
|
||||
static glong
|
||||
find_maximum_supported_tv_sec (void)
|
||||
{
|
||||
glong highest_success = 0, lowest_failure = G_MAXLONG;
|
||||
GTimeVal tv;
|
||||
GDateTime *dt = NULL;
|
||||
|
||||
tv.tv_usec = 0;
|
||||
|
||||
/* Corner case of all glong values being valid. */
|
||||
tv.tv_sec = G_MAXLONG;
|
||||
dt = g_date_time_new_from_timeval_utc (&tv);
|
||||
if (dt != NULL)
|
||||
{
|
||||
highest_success = tv.tv_sec;
|
||||
g_date_time_unref (dt);
|
||||
}
|
||||
|
||||
while (highest_success < lowest_failure - 1)
|
||||
{
|
||||
GDateTime *dt;
|
||||
|
||||
tv.tv_sec = (highest_success + lowest_failure) / 2;
|
||||
tv.tv_sec = highest_success + (lowest_failure - highest_success) / 2;
|
||||
dt = g_date_time_new_from_timeval_utc (&tv);
|
||||
|
||||
if (dt != NULL)
|
||||
|
Loading…
Reference in New Issue
Block a user