summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2019-02-25 12:36:43 +0000
committerPhilip Withnall <withnall@endlessm.com>2019-02-25 12:38:08 +0000
commit7bf49c8df7858dd6df6f9b9312327d7a1e015573 (patch)
tree2ac77010a70bd55eae506d3cc1cba7f67689b9ad
parent1fb31a16c306e3101c04074070ae1a154801d260 (diff)
downloadgvdb-7bf49c8df7858dd6df6f9b9312327d7a1e015573.tar.gz
Fix size of preallocated array
Commit 084e1d868 added a preallocation to an array to avoid reallocations later on, but neglected the fact that after N insertions into the array, there’s always a NULL terminator added to the end. Fix the preallocation to include that NULL terminator. This doesn’t change the correctness of the code, but should eliminate one reallocation. Spotted by Sebastian Dröge. See https://gitlab.gnome.org/GNOME/glib/merge_requests/674. Signed-off-by: Philip Withnall <withnall@endlessm.com>
-rw-r--r--gvdb-reader.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/gvdb-reader.c b/gvdb-reader.c
index 9509388..ccae40e 100644
--- a/gvdb-reader.c
+++ b/gvdb-reader.c
@@ -462,7 +462,7 @@ gvdb_table_get_names (GvdbTable *table,
{
GPtrArray *fixed_names;
- fixed_names = g_ptr_array_sized_new (n_names);
+ fixed_names = g_ptr_array_sized_new (n_names + 1 /* NULL terminator */);
for (i = 0; i < n_names; i++)
if (names[i] != NULL)
g_ptr_array_add (fixed_names, names[i]);