From 2e7d3dcf7082e7f09b84b62cc68bd6b38bde39f9 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 14 Oct 2020 13:04:44 +0100 Subject: [PATCH] tests: Add some additional assertions to avoid scan-build warnings This should avoid warnings like: ``` ../../../glib/tests/regex.c:715:7: warning: Array access (from variable 'matches') results in a null pointer dereference g_assert_cmpstr (l_exp->data, ==, matches[i]); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../../glib/gtestutils.h:43:79: note: expanded from macro 'g_assert_cmpstr' const char *__s1 = (s1), *__s2 = (s2); \ ^~~~ ../../../glib/tests/regex.c:803:7: warning: Array access (from variable 'tokens') results in a null pointer dereference g_assert_cmpstr (l_exp->data, ==, tokens[i]); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../../glib/gtestutils.h:43:79: note: expanded from macro 'g_assert_cmpstr' const char *__s1 = (s1), *__s2 = (s2); \ ^~~~ ../../../glib/tests/regex.c:886:7: warning: Array access (from variable 'tokens') results in a null pointer dereference g_assert_cmpstr (l_exp->data, ==, tokens[i]); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../../glib/gtestutils.h:43:79: note: expanded from macro 'g_assert_cmpstr' const char *__s1 = (s1), *__s2 = (s2); \ ^~~~ ../../../glib/tests/regex.c:918:7: warning: Array access (from variable 'tokens') results in a null pointer dereference g_assert_cmpstr (l_exp->data, ==, tokens[i]); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../../glib/gtestutils.h:43:79: note: expanded from macro 'g_assert_cmpstr' const char *__s1 = (s1), *__s2 = (s2); \ ^~~~ ``` Signed-off-by: Philip Withnall --- glib/tests/regex.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/glib/tests/regex.c b/glib/tests/regex.c index ee9cd21ca..1ea6f9288 100644 --- a/glib/tests/regex.c +++ b/glib/tests/regex.c @@ -712,6 +712,7 @@ test_fetch_all (gconstpointer d) l_exp = data->expected; for (i = 0; l_exp != NULL; i++, l_exp = g_slist_next (l_exp)) { + g_assert_nonnull (matches); g_assert_cmpstr (l_exp->data, ==, matches[i]); } @@ -800,6 +801,7 @@ test_split_simple (gconstpointer d) l_exp = data->expected; for (i = 0; l_exp != NULL; i++, l_exp = g_slist_next (l_exp)) { + g_assert_nonnull (tokens); g_assert_cmpstr (l_exp->data, ==, tokens[i]); } @@ -883,6 +885,7 @@ test_split_full (gconstpointer d) l_exp = data->expected; for (i = 0; l_exp != NULL; i++, l_exp = g_slist_next (l_exp)) { + g_assert_nonnull (tokens); g_assert_cmpstr (l_exp->data, ==, tokens[i]); } @@ -915,6 +918,7 @@ test_split (gconstpointer d) l_exp = data->expected; for (i = 0; l_exp != NULL; i++, l_exp = g_slist_next (l_exp)) { + g_assert_nonnull (tokens); g_assert_cmpstr (l_exp->data, ==, tokens[i]); }