Commit 428acd9b authored by Philip Withnall's avatar Philip Withnall

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's avatarPhilip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=783841
parent 30fed3b9
......@@ -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;
while (highest_success < lowest_failure - 1)
/* 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)
{
GDateTime *dt;
highest_success = tv.tv_sec;
g_date_time_unref (dt);
}
tv.tv_sec = (highest_success + lowest_failure) / 2;
while (highest_success < lowest_failure - 1)
{
tv.tv_sec = highest_success + (lowest_failure - highest_success) / 2;
dt = g_date_time_new_from_timeval_utc (&tv);
if (dt != NULL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment