After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 763339 - array: Support clearing an empty array with g_array_remove_range()
array: Support clearing an empty array with g_array_remove_range()
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2016-03-08 19:02 UTC by Philip Withnall
Modified: 2016-03-09 14:44 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
array: Support clearing an empty array with g_array_remove_range() (2.71 KB, patch)
2016-03-08 19:03 UTC, Philip Withnall
none Details | Review
array: Support clearing an empty array with g_array_remove_range() (2.77 KB, patch)
2016-03-09 07:52 UTC, Philip Withnall
committed Details | Review

Description Philip Withnall 2016-03-08 19:02:54 UTC
Trivial patch attached, including unit tests.
Comment 1 Philip Withnall 2016-03-08 19:03:05 UTC
Created attachment 323425 [details] [review]
array: Support clearing an empty array with g_array_remove_range()

Previously, calling g_array_remove_range(array, 0, array->len) on an
empty array would result in a precondition failure in
g_array_remove_range(), as the given start index (0), was not strictly
less than the array length (0).

Disable that precondition check if the number of elements to remove is
zero.
Comment 2 Allison Karlitskaya (desrt) 2016-03-08 19:05:40 UTC
Review of attachment 323425 [details] [review]:

Thanks for the patch.

I think the patch would be better if it changed the 'index < len' check to 'index <= len'.  This would allow removing 0 items from the end of any array -- not just empty ones.
Comment 3 Allison Karlitskaya (desrt) 2016-03-08 19:11:19 UTC
Sorry.  I misread the patch a bit, so my analysis was not correct; I still stand by my original suggestion since I think it reads nicer without treating '0' as a special case.
Comment 4 Philip Withnall 2016-03-09 07:52:57 UTC
Created attachment 323478 [details] [review]
array: Support clearing an empty array with g_array_remove_range()

Previously, calling g_array_remove_range(array, 0, array->len) on an
empty array would result in a precondition failure in
g_array_remove_range(), as the given start index (0), was not strictly
less than the array length (0).

Allow the index to equal the array length, so that zero elements can be
removed from any array. A subsequent check makes sure that the array
length is not overflowed by the index + length.
Comment 5 Allison Karlitskaya (desrt) 2016-03-09 14:19:39 UTC
Review of attachment 323478 [details] [review]:

Looks good.  Thanks!
Comment 6 Philip Withnall 2016-03-09 14:44:36 UTC
Attachment 323478 [details] pushed as 37756a0 - array: Support clearing an empty array with g_array_remove_range()