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:
Simon McVittie 2023-01-10 13:40:24 +00:00
parent cabe1370ed
commit 952b07101f

View File

@ -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));
}