mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-03 09:46:17 +01:00
garray: Add assertions to help static analysis
In both these cases, the static analyser (Coverity) was worrying that the array `data`/`pdata` wasn’t allocated before an element was written to. That was a false positive: all the necessary conditions are met in both cases for `g_{ptr_,}array_maybe_expand()` to always allocate the array. But it makes things a bit easier for the analyser if we add an assertion to double-check that. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Coverity CID: #1474426, #1489512
This commit is contained in:
parent
5f945e5464
commit
8b863cfd78
@ -285,7 +285,8 @@ g_array_sized_new (gboolean zero_terminated,
|
||||
if (array->zero_terminated || reserved_size != 0)
|
||||
{
|
||||
g_array_maybe_expand (array, reserved_size);
|
||||
g_array_zero_terminate(array);
|
||||
g_assert (array->data != NULL);
|
||||
g_array_zero_terminate (array);
|
||||
}
|
||||
|
||||
return (GArray*) array;
|
||||
@ -1120,7 +1121,10 @@ ptr_array_new (guint reserved_size,
|
||||
if (G_LIKELY (reserved_size < G_MAXUINT) &&
|
||||
null_terminated)
|
||||
reserved_size++;
|
||||
|
||||
g_ptr_array_maybe_expand (array, reserved_size);
|
||||
g_assert (array->pdata != NULL);
|
||||
|
||||
if (null_terminated)
|
||||
{
|
||||
/* don't use ptr_array_maybe_null_terminate(). It helps the compiler
|
||||
|
Loading…
Reference in New Issue
Block a user