gtestutils: Add an assertion to squash a scan-build false positive

scan-build thinks there’s a potential `NULL` pointer dereference of some
of the members of `msg->strings`, because it doesn’t know about the
implicit invariant that the length of `msg->strings` is
`msg->n_strings`.

Ideally we want an assertion like `g_assert (g_strv_length
(msg->strings) == msg->n_strings)`, but that’s not very performant, so
just settle for a non-`NULL` assertion on each loop iteration to give
scan-build the hint it needs.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1767
This commit is contained in:
Philip Withnall 2024-04-12 17:41:09 +01:00
parent cf940496df
commit 2d5fc78f63
No known key found for this signature in database
GPG Key ID: DCDF5885B1F3ED73

View File

@ -4308,7 +4308,9 @@ g_test_log_dump (GTestLogMsg *msg,
gstring_append_int (gstring, 0); /* reserved */
for (ui = 0; ui < msg->n_strings; ui++)
{
guint l = strlen (msg->strings[ui]);
guint l;
g_assert (msg->strings[ui] != NULL);
l = strlen (msg->strings[ui]);
gstring_append_int (gstring, l);
g_string_append_len (gstring, msg->strings[ui], l);
}