mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-03 09:46:17 +01:00
array: Avoid use of memcpy(dest, NULL, 0)
glibc declares memcpy() with the first two arguments (the pointers) annotated as non-null via an attribute, which results in the undefined behaviour sanitizer considering it to be UB to pass a null pointer in the second argument, even if we are copying 0 bytes (and hence not actually dereferencing the pointer). This shows up in array-test when run with the undefined behaviour sanitizer. Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
parent
8a7b375216
commit
3837b83f5a
@ -1146,7 +1146,7 @@ g_ptr_array_copy (GPtrArray *array,
|
|||||||
for (i = 0; i < array->len; i++)
|
for (i = 0; i < array->len; i++)
|
||||||
new_array->pdata[i] = func (array->pdata[i], user_data);
|
new_array->pdata[i] = func (array->pdata[i], user_data);
|
||||||
}
|
}
|
||||||
else
|
else if (array->len > 0)
|
||||||
{
|
{
|
||||||
memcpy (new_array->pdata, array->pdata,
|
memcpy (new_array->pdata, array->pdata,
|
||||||
array->len * sizeof (*array->pdata));
|
array->len * sizeof (*array->pdata));
|
||||||
@ -1797,7 +1797,7 @@ g_ptr_array_extend (GPtrArray *array_to_extend,
|
|||||||
rarray_to_extend->pdata[i + rarray_to_extend->len] =
|
rarray_to_extend->pdata[i + rarray_to_extend->len] =
|
||||||
func (array->pdata[i], user_data);
|
func (array->pdata[i], user_data);
|
||||||
}
|
}
|
||||||
else
|
else if (array->len > 0)
|
||||||
{
|
{
|
||||||
memcpy (rarray_to_extend->pdata + rarray_to_extend->len, array->pdata,
|
memcpy (rarray_to_extend->pdata + rarray_to_extend->len, array->pdata,
|
||||||
array->len * sizeof (*array->pdata));
|
array->len * sizeof (*array->pdata));
|
||||||
|
Loading…
Reference in New Issue
Block a user