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.
This commit is contained in:
Emmanuele Bassi 2022-09-02 12:46:57 +01:00
parent 66c4e35e28
commit 903c004b37
3 changed files with 6 additions and 12 deletions

View File

@ -124,8 +124,7 @@ test_object_set_property (GObject *gobject,
TestObject *tobj = (TestObject *) gobject; TestObject *tobj = (TestObject *) gobject;
g_assert_cmpint (prop_id, !=, 0); g_assert_cmpint (prop_id, !=, 0);
g_assert_cmpint (prop_id, !=, N_PROPERTIES); g_assert_true (prop_id < N_PROPERTIES && pspec == properties[prop_id]);
g_assert (pspec == properties[prop_id]);
switch ((TestObjectProperty)prop_id) switch ((TestObjectProperty)prop_id)
{ {
@ -159,8 +158,7 @@ test_object_get_property (GObject *gobject,
TestObject *tobj = (TestObject *) gobject; TestObject *tobj = (TestObject *) gobject;
g_assert_cmpint (prop_id, !=, 0); g_assert_cmpint (prop_id, !=, 0);
g_assert_cmpint (prop_id, !=, N_PROPERTIES); g_assert_true (prop_id < N_PROPERTIES && pspec == properties[prop_id]);
g_assert (pspec == properties[prop_id]);
switch ((TestObjectProperty)prop_id) switch ((TestObjectProperty)prop_id)
{ {

View File

@ -132,8 +132,7 @@ test_object_set_property (GObject *gobject,
TestObject *tobj = (TestObject *) gobject; TestObject *tobj = (TestObject *) gobject;
g_assert_cmpint (prop_id, !=, 0); g_assert_cmpint (prop_id, !=, 0);
g_assert_cmpint (prop_id, !=, N_PROPERTIES); g_assert_true (prop_id < N_PROPERTIES && pspec == properties[prop_id]);
g_assert (pspec == properties[prop_id]);
switch ((TestObjectProperty)prop_id) switch ((TestObjectProperty)prop_id)
{ {
@ -167,8 +166,7 @@ test_object_get_property (GObject *gobject,
TestObject *tobj = (TestObject *) gobject; TestObject *tobj = (TestObject *) gobject;
g_assert_cmpint (prop_id, !=, 0); g_assert_cmpint (prop_id, !=, 0);
g_assert_cmpint (prop_id, !=, N_PROPERTIES); g_assert_true (prop_id < N_PROPERTIES && pspec == properties[prop_id]);
g_assert (pspec == properties[prop_id]);
switch ((TestObjectProperty)prop_id) switch ((TestObjectProperty)prop_id)
{ {

View File

@ -104,8 +104,7 @@ test_object_set_property (GObject *gobject,
TestObject *tobj = (TestObject *) gobject; TestObject *tobj = (TestObject *) gobject;
g_assert_cmpint (prop_id, !=, 0); g_assert_cmpint (prop_id, !=, 0);
g_assert_cmpint (prop_id, !=, N_PROPERTIES); g_assert_true (prop_id < N_PROPERTIES && pspec == properties[prop_id]);
g_assert (pspec == properties[prop_id]);
switch (prop_id) switch (prop_id)
{ {
@ -139,8 +138,7 @@ test_object_get_property (GObject *gobject,
TestObject *tobj = (TestObject *) gobject; TestObject *tobj = (TestObject *) gobject;
g_assert_cmpint (prop_id, !=, 0); g_assert_cmpint (prop_id, !=, 0);
g_assert_cmpint (prop_id, !=, N_PROPERTIES); g_assert_true (prop_id < N_PROPERTIES && pspec == properties[prop_id]);
g_assert (pspec == properties[prop_id]);
switch (prop_id) switch (prop_id)
{ {