[gvdb: 1/2] Fix size of preallocated array
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvdb: 1/2] Fix size of preallocated array
- Date: Mon, 25 Feb 2019 12:39:19 +0000 (UTC)
commit 7bf49c8df7858dd6df6f9b9312327d7a1e015573
Author: Philip Withnall <withnall endlessm com>
Date: Mon Feb 25 12:36:43 2019 +0000
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>
gvdb-reader.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
---
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]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]