From: Dan Winship Date: Wed, 22 Feb 2012 13:12:52 +0000 (-0500) Subject: gasyncqueue: fix a 32bit overflow in g_async_queue_timed_pop X-Git-Tag: android-x86-6.0-r1~424 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=88182d375e13ae6519a288d5295220c83ca27e73;p=android-x86%2Fexternal-bluetooth-glib.git gasyncqueue: fix a 32bit overflow in g_async_queue_timed_pop also, add a test for g_async_queue_timed_pop() and g_async_queue_timeout_pop() to tests/asyncqueue.c https://bugzilla.gnome.org/show_bug.cgi?id=669670 --- diff --git a/glib/gasyncqueue.c b/glib/gasyncqueue.c index dab487cb2..31976bcea 100644 --- a/glib/gasyncqueue.c +++ b/glib/gasyncqueue.c @@ -602,7 +602,7 @@ g_async_queue_timed_pop (GAsyncQueue *queue, if (end_time != NULL) { m_end_time = g_get_monotonic_time () + - (end_time->tv_sec * G_USEC_PER_SEC + end_time->tv_usec - + ((gint64)end_time->tv_sec * G_USEC_PER_SEC + end_time->tv_usec - g_get_real_time ()); } else diff --git a/glib/tests/asyncqueue.c b/glib/tests/asyncqueue.c index ce106469f..21b672f7a 100644 --- a/glib/tests/asyncqueue.c +++ b/glib/tests/asyncqueue.c @@ -169,6 +169,40 @@ test_async_queue_threads (void) g_assert_cmpint (c, ==, 1000); } +static void +test_async_queue_timed (void) +{ + GAsyncQueue *q; + GTimeVal tv; + gint64 start, end, diff; + gpointer val; + + q = g_async_queue_new (); + + start = g_get_monotonic_time (); + val = g_async_queue_timeout_pop (q, G_USEC_PER_SEC / 10); + g_assert (val == NULL); + + end = g_get_monotonic_time (); + diff = end - start; + g_assert_cmpint (diff, >=, G_USEC_PER_SEC / 10); + /* diff should be only a little bit more than G_USEC_PER_SEC/10, but + * we have to leave some wiggle room for heavily-loaded machines... + */ + g_assert_cmpint (diff, <, G_USEC_PER_SEC); + + start = end; + g_get_current_time (&tv); + g_time_val_add (&tv, G_USEC_PER_SEC / 10); + val = g_async_queue_timed_pop (q, &tv); + g_assert (val == NULL); + + end = g_get_monotonic_time (); + diff = end - start; + g_assert_cmpint (diff, >=, G_USEC_PER_SEC / 10); + g_assert_cmpint (diff, <, G_USEC_PER_SEC); +} + int main (int argc, char *argv[]) { @@ -177,6 +211,7 @@ main (int argc, char *argv[]) g_test_add_func ("/asyncqueue/sort", test_async_queue_sort); g_test_add_func ("/asyncqueue/destroy", test_async_queue_destroy); g_test_add_func ("/asyncqueue/threads", test_async_queue_threads); + g_test_add_func ("/asyncqueue/timed", test_async_queue_timed); return g_test_run (); }