diff options
author | Thomas Haller <thaller@redhat.com> | 2021-01-25 16:39:42 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-01-25 16:47:18 +0100 |
commit | a5089952aac4c3df47fa16154a6986ab75294c2e (patch) | |
tree | d82a9c696a021dc3ed716b9716c3ae7bedd8107b | |
parent | 9155e076fc9f28192c13f693c2a8bf6cdf0d7022 (diff) | |
download | glib-th/g-ptr-array-set-null-terminated.tar.gz |
fixup! array: add support for %NULL termination in GPtrArrayth/g-ptr-array-set-null-terminated
-rw-r--r-- | glib/garray.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/glib/garray.c b/glib/garray.c index 8e2cd56a6..8cd9e2cac 100644 --- a/glib/garray.c +++ b/glib/garray.c @@ -1511,8 +1511,8 @@ g_ptr_array_unref (GPtrArray *array) * function has been set for @array. * * Note that if the array is %NULL terminated and @free_seg is %FALSE - * and the pdata is %NULL (and the length is zero), the this function - * will return %NULL too and not allocate an empty %NULL terminated buffer. + * then this will always return an allocated %NULL termianted buffer. + * If pdata is previously %NULL, a new buffer will be allocated. * * This function is not thread-safe. If using a #GPtrArray from multiple * threads, use only the atomic g_ptr_array_ref() and g_ptr_array_unref() @@ -1569,7 +1569,11 @@ ptr_array_free (GPtrArray *array, segment = NULL; } else - segment = rarray->pdata; + { + segment = rarray->pdata; + if (!segment && rarray->null_terminated) + segment = (gpointer *) g_new0 (char *, 1); + } if (flags & PRESERVE_WRAPPER) { |