From 7bf49c8df7858dd6df6f9b9312327d7a1e015573 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 25 Feb 2019 12:36:43 +0000 Subject: [PATCH] Fix size of preallocated array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- gvdb-reader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gvdb-reader.c b/gvdb-reader.c index 95093885f..ccae40e64 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]);