gvariant-serialiser: Add an assertion to help the static analyser

scan-build thinks that `gvs_variable_sized_array_is_normal()` can do a
`NULL` pointer dereference on `value.data` when `value.size == 0`. This
isn’t possible, because `offsets.length == 0` always when `value.size ==
0`, but that’s a bit of a complex relationship which the static analyser
can’t work out.

Give it some help by adding an assertion.

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

Helps: #1767
This commit is contained in:
Philip Withnall 2024-04-09 16:41:28 +01:00
parent 3e68debb13
commit 62b5c738e7
No known key found for this signature in database
GPG Key ID: DCDF5885B1F3ED73

View File

@ -904,6 +904,8 @@ gvs_variable_sized_array_is_normal (GVariantSerialised value)
if (value.size != 0 && offsets.length == 0) if (value.size != 0 && offsets.length == 0)
return FALSE; return FALSE;
g_assert (value.size != 0 || offsets.length == 0);
child.type_info = g_variant_type_info_element (value.type_info); child.type_info = g_variant_type_info_element (value.type_info);
g_variant_type_info_query (child.type_info, &alignment, NULL); g_variant_type_info_query (child.type_info, &alignment, NULL);
child.depth = value.depth + 1; child.depth = value.depth + 1;