diff options
author | Philip Withnall <philip.withnall@collabora.co.uk> | 2016-03-08 18:59:34 +0000 |
---|---|---|
committer | Philip Withnall <philip.withnall@collabora.co.uk> | 2016-03-09 07:50:07 +0000 |
commit | 37756a06c9c8821e4cbc22218046b88cdc85ca90 (patch) | |
tree | d27f45cf87817ddbdbdf630233696eb909d0102e /glib/tests | |
parent | 7d3d948947f6854507ba62e215ea681b9ef7dad3 (diff) | |
download | glib-37756a06c9c8821e4cbc22218046b88cdc85ca90.tar.gz |
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.
https://bugzilla.gnome.org/show_bug.cgi?id=763339
Diffstat (limited to 'glib/tests')
-rw-r--r-- | glib/tests/array-test.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/glib/tests/array-test.c b/glib/tests/array-test.c index 86b613a7f..a0074d4c3 100644 --- a/glib/tests/array-test.c +++ b/glib/tests/array-test.c @@ -168,6 +168,10 @@ array_remove_range (void) prev = cur; } + /* Ensure the entire array can be cleared, even when empty. */ + g_array_remove_range (garray, 0, garray->len); + g_array_remove_range (garray, 0, garray->len); + g_array_free (garray, TRUE); } @@ -711,6 +715,10 @@ byte_array_remove_range (void) g_assert (gbarray->data[4*i+3] == 'd'); } + /* Ensure the entire array can be cleared, even when empty. */ + g_byte_array_remove_range (gbarray, 0, gbarray->len); + g_byte_array_remove_range (gbarray, 0, gbarray->len); + g_byte_array_free (gbarray, TRUE); } |