GNOME Bugzilla – Bug 795975
Fix g_array_insert_vals() with an index off the end of the array
Last modified: 2018-05-24 20:31:34 UTC
Currently, calling g_array_insert_vals() with an index which is off the end of the array results in a crash in memmove(). Given that GArray supports clearing newly created elements when setting the array larger than its current size using g_array_set_size(), it seems appropriate to allow this with g_array_insert_vals(). Patch series coming up which fixes this and adds lots of test coverage for various bits of GArray (from looking at the missing branch coverage on our existing tests: https://gnome.pages.gitlab.gnome.org/glib/coverage/glib/garray.c.gcov.html). If we decide we want to disallow g_array_insert_vals() from being called with out-of-bounds indexes, that’s also fine; I can rearrange the patches to add a g_return_val_if_fail() on the index instead (as per bug #414301).
*** Bug 414301 has been marked as a duplicate of this bug. ***
Created attachment 371845 [details] [review] garray: Fix (nullable) annotation on GArray.[prepend|insert]_vals() They do both accept NULL value arrays, but only if the number of elements in the value array is zero. Fix the annotations and mention this in the documentation. Signed-off-by: Philip Withnall <withnall@endlessm.com>
Created attachment 371846 [details] [review] garray: Allow over-allocation in g_array_insert_vals() Previously, g_array_insert_vals() would crash if called with an index off the end of the array. This is inconsistent with the behaviour of other methods (like g_array_set_size()), which will expand the array as necessary. Modify g_array_insert_vals() to expand the array as necessary. New array elements will be cleared to zero if the GArray was constructed with (clear_ == TRUE). Signed-off-by: Philip Withnall <withnall@endlessm.com>
Created attachment 371847 [details] [review] tests: Expand GArray test coverage to cover all construction forms Previously, there was very little coverage of GArray behaviour with either of the zero_terminated or clear_ arguments to g_array_new() set to TRUE. Parameterise the tests and exhaustively expand the coverage to cover all possible GArray configurations. This was made possible by the online code coverage report for GLib which we now have: https://gnome.pages.gitlab.gnome.org/glib/coverage/glib/garray.c.gcov.html. Signed-off-by: Philip Withnall <withnall@endlessm.com>
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/1374.