GNOME Bugzilla – Bug 763339
array: Support clearing an empty array with g_array_remove_range()
Last modified: 2016-03-09 14:44:45 UTC
Trivial patch attached, including unit tests.
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.
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.
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.
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.
Review of attachment 323478 [details] [review]: Looks good. Thanks!
Attachment 323478 [details] pushed as 37756a0 - array: Support clearing an empty array with g_array_remove_range()