From 065dea99f4c78695391c50bbd1c365b1628a5286 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 17 Nov 2020 10:31:59 +0000 Subject: [PATCH 1/2] gtestutils: Drop unnecessary NULL check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The macro wrapper to `g_assertion_message_cmpstrv()` makes sure that neither array is `NULL`, so there’s no need for a second `NULL` check. Additionally, this check happens after the arrays have already been dereferenced, at which point the program would have crashed if the arrays were `NULL`. Signed-off-by: Philip Withnall Coverity CID: #1436406, #1436407 --- glib/gtestutils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glib/gtestutils.c b/glib/gtestutils.c index 1bc6aa2f3..d48368830 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -3055,8 +3055,8 @@ g_assertion_message_cmpstrv (const char *domain, const char *s1 = arg1[first_wrong_idx], *s2 = arg2[first_wrong_idx]; char *a1, *a2, *s, *t1 = NULL, *t2 = NULL; - a1 = arg1 ? g_strconcat ("\"", t1 = g_strescape (s1, NULL), "\"", NULL) : g_strdup ("NULL"); - a2 = arg2 ? g_strconcat ("\"", t2 = g_strescape (s2, NULL), "\"", NULL) : g_strdup ("NULL"); + a1 = g_strconcat ("\"", t1 = g_strescape (s1, NULL), "\"", NULL); + a2 = g_strconcat ("\"", t2 = g_strescape (s2, NULL), "\"", NULL); g_free (t1); g_free (t2); s = g_strdup_printf ("assertion failed (%s): first differing element at index %" G_GSIZE_FORMAT ": %s does not equal %s", From 51f322b74c6070fb295f577759b9a25228eb3a21 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 17 Nov 2020 10:38:12 +0000 Subject: [PATCH 2/2] tests: Add missing assertion to guard against infinite loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the loop variable changed signedness, it’s now possible for there to be an infinite loop if `get_match_count()` returns an error. Guard against that. Signed-off-by: Philip Withnall Coverity CID: #1436405 --- glib/tests/regex.c | 1 + 1 file changed, 1 insertion(+) diff --git a/glib/tests/regex.c b/glib/tests/regex.c index d86d32f9b..c57bd8cdc 100644 --- a/glib/tests/regex.c +++ b/glib/tests/regex.c @@ -1316,6 +1316,7 @@ test_match_all (gconstpointer d) g_assert (match_ok); match_count = g_match_info_get_match_count (match_info); + g_assert_cmpint (match_count, >=, 0); if (match_count != g_slist_length (data->expected)) {