mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-05 02:36:19 +01:00
garray: Update NULL termination after copying array content
ptr_array_new(len, ., TRUE) ensures that there are at least len+1 elements in pdata, and that pdata[0] is null, but leaves the rest of pdata uninitialized. After copying the array data into pdata[1] to pdata[len-1] inclusive, we still need to make sure pdata[len] is a null terminator. Note that if len is 0, then pdata is not guaranteed to be non-null. If it's null, then we can't add null-termination to it until its size is updated. Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2877 Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
parent
cabe1370ed
commit
68b9fd53ec
@ -1387,6 +1387,9 @@ ptr_array_new_from_array (gpointer *data,
|
||||
memcpy (rarray->pdata, data, len * sizeof (gpointer));
|
||||
}
|
||||
|
||||
if (null_terminated && rarray->pdata != NULL)
|
||||
rarray->pdata[len] = NULL;
|
||||
|
||||
rarray->len = len;
|
||||
|
||||
return array;
|
||||
|
Loading…
Reference in New Issue
Block a user