mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-23 10:42:11 +01:00
tests: Fix a scan-build warning about uninitialised variables
It’s a false positive, but points to a slightly unnecessary use of a global variable to store something which could be computed per-test. scan-build thought that arrays of size `n_handlers` could have uninitialised values accessed in them if `n_handlers` were to change value part-way through a test (which it didn’t). Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
parent
a0f124e67c
commit
683cf0a1ba
@ -45,7 +45,11 @@ nop (void)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static guint n_handlers = 0;
|
static guint
|
||||||
|
choose_n_handlers (void)
|
||||||
|
{
|
||||||
|
return g_test_perf () ? 500000 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_connect_many (void)
|
test_connect_many (void)
|
||||||
@ -53,6 +57,7 @@ test_connect_many (void)
|
|||||||
MyObj *o;
|
MyObj *o;
|
||||||
gdouble time_elapsed;
|
gdouble time_elapsed;
|
||||||
guint i;
|
guint i;
|
||||||
|
const guint n_handlers = choose_n_handlers ();
|
||||||
|
|
||||||
o = g_object_new (my_obj_get_type (), NULL);
|
o = g_object_new (my_obj_get_type (), NULL);
|
||||||
|
|
||||||
@ -75,6 +80,7 @@ test_disconnect_many_ordered (void)
|
|||||||
gulong *handlers;
|
gulong *handlers;
|
||||||
gdouble time_elapsed;
|
gdouble time_elapsed;
|
||||||
guint i;
|
guint i;
|
||||||
|
const guint n_handlers = choose_n_handlers ();
|
||||||
|
|
||||||
handlers = g_malloc_n (n_handlers, sizeof (*handlers));
|
handlers = g_malloc_n (n_handlers, sizeof (*handlers));
|
||||||
o = g_object_new (my_obj_get_type (), NULL);
|
o = g_object_new (my_obj_get_type (), NULL);
|
||||||
@ -102,6 +108,7 @@ test_disconnect_many_inverse (void)
|
|||||||
gulong *handlers;
|
gulong *handlers;
|
||||||
gdouble time_elapsed;
|
gdouble time_elapsed;
|
||||||
guint i;
|
guint i;
|
||||||
|
const guint n_handlers = choose_n_handlers ();
|
||||||
|
|
||||||
handlers = g_malloc_n (n_handlers, sizeof (*handlers));
|
handlers = g_malloc_n (n_handlers, sizeof (*handlers));
|
||||||
o = g_object_new (my_obj_get_type (), NULL);
|
o = g_object_new (my_obj_get_type (), NULL);
|
||||||
@ -130,6 +137,7 @@ test_disconnect_many_random (void)
|
|||||||
gulong id;
|
gulong id;
|
||||||
gdouble time_elapsed;
|
gdouble time_elapsed;
|
||||||
guint i, j;
|
guint i, j;
|
||||||
|
const guint n_handlers = choose_n_handlers ();
|
||||||
|
|
||||||
handlers = g_malloc_n (n_handlers, sizeof (*handlers));
|
handlers = g_malloc_n (n_handlers, sizeof (*handlers));
|
||||||
o = g_object_new (my_obj_get_type (), NULL);
|
o = g_object_new (my_obj_get_type (), NULL);
|
||||||
@ -166,6 +174,7 @@ test_disconnect_2_signals (void)
|
|||||||
gulong id;
|
gulong id;
|
||||||
gdouble time_elapsed;
|
gdouble time_elapsed;
|
||||||
guint i, j;
|
guint i, j;
|
||||||
|
const guint n_handlers = choose_n_handlers ();
|
||||||
|
|
||||||
handlers = g_malloc_n (n_handlers, sizeof (*handlers));
|
handlers = g_malloc_n (n_handlers, sizeof (*handlers));
|
||||||
o = g_object_new (my_obj_get_type (), NULL);
|
o = g_object_new (my_obj_get_type (), NULL);
|
||||||
@ -208,6 +217,7 @@ test_disconnect_2_objects (void)
|
|||||||
gulong id;
|
gulong id;
|
||||||
gdouble time_elapsed;
|
gdouble time_elapsed;
|
||||||
guint i, j;
|
guint i, j;
|
||||||
|
const guint n_handlers = choose_n_handlers ();
|
||||||
|
|
||||||
handlers = g_malloc_n (n_handlers, sizeof (*handlers));
|
handlers = g_malloc_n (n_handlers, sizeof (*handlers));
|
||||||
objects = g_malloc_n (n_handlers, sizeof (*objects));
|
objects = g_malloc_n (n_handlers, sizeof (*objects));
|
||||||
@ -262,6 +272,7 @@ test_block_many (void)
|
|||||||
gulong id;
|
gulong id;
|
||||||
gdouble time_elapsed;
|
gdouble time_elapsed;
|
||||||
guint i, j;
|
guint i, j;
|
||||||
|
const guint n_handlers = choose_n_handlers ();
|
||||||
|
|
||||||
handlers = g_malloc_n (n_handlers, sizeof (*handlers));
|
handlers = g_malloc_n (n_handlers, sizeof (*handlers));
|
||||||
o = g_object_new (my_obj_get_type (), NULL);
|
o = g_object_new (my_obj_get_type (), NULL);
|
||||||
@ -298,8 +309,6 @@ main (int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
n_handlers = g_test_perf () ? 500000 : 1;
|
|
||||||
|
|
||||||
g_test_add_func ("/signal/handler/connect-many", test_connect_many);
|
g_test_add_func ("/signal/handler/connect-many", test_connect_many);
|
||||||
g_test_add_func ("/signal/handler/disconnect-many-ordered", test_disconnect_many_ordered);
|
g_test_add_func ("/signal/handler/disconnect-many-ordered", test_disconnect_many_ordered);
|
||||||
g_test_add_func ("/signal/handler/disconnect-many-inverse", test_disconnect_many_inverse);
|
g_test_add_func ("/signal/handler/disconnect-many-inverse", test_disconnect_many_inverse);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user