mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-26 20:22:11 +01:00
garray: Avoid calling memcpy with no items
`memcpy(NULL, ., n)` and `memcpy(., NULL, n)` are undefined behaviour, even if *n* is zero. When len is 0 here, callers are allowed to pass in null data, and GPtrArray also does not guarantee to have allocated rarray->pdata yet. Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
parent
cabe1370ed
commit
952b07101f
@ -1382,7 +1382,7 @@ ptr_array_new_from_array (gpointer *data,
|
||||
for (gsize i = 0; i < len; i++)
|
||||
rarray->pdata[i] = copy_func (data[i], copy_func_user_data);
|
||||
}
|
||||
else
|
||||
else if (len != 0)
|
||||
{
|
||||
memcpy (rarray->pdata, data, len * sizeof (gpointer));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user