From 903c004b37d723972b07ecbdd880ae0d2c8b767d Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 2 Sep 2022 12:46:57 +0100 Subject: [PATCH 1/2] Fix array-bounds compiler warnings with GCC 12 GCC isn't smart enough to recognise that the assertion on the size of N_PROPERTIES also affects the assertion on the GParamSpec array access, so we need to coalesce the two checks into one to avoid an array-bounds compiler warning. --- gobject/tests/notify-init.c | 6 ++---- gobject/tests/notify-init2.c | 6 ++---- gobject/tests/properties.c | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/gobject/tests/notify-init.c b/gobject/tests/notify-init.c index 99c628593..17500cbe9 100644 --- a/gobject/tests/notify-init.c +++ b/gobject/tests/notify-init.c @@ -124,8 +124,7 @@ test_object_set_property (GObject *gobject, TestObject *tobj = (TestObject *) gobject; g_assert_cmpint (prop_id, !=, 0); - g_assert_cmpint (prop_id, !=, N_PROPERTIES); - g_assert (pspec == properties[prop_id]); + g_assert_true (prop_id < N_PROPERTIES && pspec == properties[prop_id]); switch ((TestObjectProperty)prop_id) { @@ -159,8 +158,7 @@ test_object_get_property (GObject *gobject, TestObject *tobj = (TestObject *) gobject; g_assert_cmpint (prop_id, !=, 0); - g_assert_cmpint (prop_id, !=, N_PROPERTIES); - g_assert (pspec == properties[prop_id]); + g_assert_true (prop_id < N_PROPERTIES && pspec == properties[prop_id]); switch ((TestObjectProperty)prop_id) { diff --git a/gobject/tests/notify-init2.c b/gobject/tests/notify-init2.c index ab6677c1d..c3ebae002 100644 --- a/gobject/tests/notify-init2.c +++ b/gobject/tests/notify-init2.c @@ -132,8 +132,7 @@ test_object_set_property (GObject *gobject, TestObject *tobj = (TestObject *) gobject; g_assert_cmpint (prop_id, !=, 0); - g_assert_cmpint (prop_id, !=, N_PROPERTIES); - g_assert (pspec == properties[prop_id]); + g_assert_true (prop_id < N_PROPERTIES && pspec == properties[prop_id]); switch ((TestObjectProperty)prop_id) { @@ -167,8 +166,7 @@ test_object_get_property (GObject *gobject, TestObject *tobj = (TestObject *) gobject; g_assert_cmpint (prop_id, !=, 0); - g_assert_cmpint (prop_id, !=, N_PROPERTIES); - g_assert (pspec == properties[prop_id]); + g_assert_true (prop_id < N_PROPERTIES && pspec == properties[prop_id]); switch ((TestObjectProperty)prop_id) { diff --git a/gobject/tests/properties.c b/gobject/tests/properties.c index da467c2fe..e30a2705b 100644 --- a/gobject/tests/properties.c +++ b/gobject/tests/properties.c @@ -104,8 +104,7 @@ test_object_set_property (GObject *gobject, TestObject *tobj = (TestObject *) gobject; g_assert_cmpint (prop_id, !=, 0); - g_assert_cmpint (prop_id, !=, N_PROPERTIES); - g_assert (pspec == properties[prop_id]); + g_assert_true (prop_id < N_PROPERTIES && pspec == properties[prop_id]); switch (prop_id) { @@ -139,8 +138,7 @@ test_object_get_property (GObject *gobject, TestObject *tobj = (TestObject *) gobject; g_assert_cmpint (prop_id, !=, 0); - g_assert_cmpint (prop_id, !=, N_PROPERTIES); - g_assert (pspec == properties[prop_id]); + g_assert_true (prop_id < N_PROPERTIES && pspec == properties[prop_id]); switch (prop_id) { From e08c954693fdcfceda2de59cca93a76125f4fca6 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 2 Sep 2022 12:52:35 +0100 Subject: [PATCH 2/2] Fix check before a memcpy The search_total_results address is always going to be non-zero, so the check will always evaluate to true, and GCC is kind enough to point this out to us. The appropriate fix is checking if the size of the search results array is larger than zero, and if so, copy them into the total results array. --- gio/gdesktopappinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c index 85b424dda..56cfa4cdb 100644 --- a/gio/gdesktopappinfo.c +++ b/gio/gdesktopappinfo.c @@ -710,7 +710,7 @@ merge_directory_results (void) static_total_results = g_renew (struct search_result, static_total_results, static_total_results_allocated); } - if (static_total_results + static_total_results_size != 0) + if (static_search_results_size != 0) memcpy (static_total_results + static_total_results_size, static_search_results, static_search_results_size * sizeof (struct search_result));