Commit 74e4b839 authored by Philip Withnall's avatar Philip Withnall

Merge branch 'bad-liststore' into 'master'

Fix overflow in GListStore

Closes #1639

See merge request !572
parents eeb657bb d8a0dcb1
Pipeline #49625 failed with stages
in 8 minutes and 10 seconds
...@@ -181,9 +181,9 @@ g_list_store_get_item (GListModel *list, ...@@ -181,9 +181,9 @@ g_list_store_get_item (GListModel *list,
if (store->last_position != -1u) if (store->last_position != -1u)
{ {
if (store->last_position == position + 1) if (position < G_MAXUINT && store->last_position == position + 1)
it = g_sequence_iter_prev (store->last_iter); it = g_sequence_iter_prev (store->last_iter);
else if (store->last_position == position - 1) else if (position > 0 && store->last_position == position - 1)
it = g_sequence_iter_next (store->last_iter); it = g_sequence_iter_next (store->last_iter);
else if (store->last_position == position) else if (store->last_position == position)
it = store->last_iter; it = store->last_iter;
......
...@@ -778,6 +778,34 @@ test_store_signal_items_changed (void) ...@@ -778,6 +778,34 @@ test_store_signal_items_changed (void)
g_object_unref (store); g_object_unref (store);
} }
/* Due to an overflow in the list store last-iter optimization,
* the sequence 'lookup 0; lookup MAXUINT' was returning the
* same item twice, and not NULL for the second lookup.
* See #1639.
*/
static void
test_store_past_end (void)
{
GListStore *store;
GListModel *model;
GSimpleAction *item;
store = g_list_store_new (G_TYPE_SIMPLE_ACTION);
model = G_LIST_MODEL (store);
item = g_simple_action_new ("2", NULL);
g_list_store_append (store, item);
g_object_unref (item);
g_assert_cmpint (g_list_model_get_n_items (model), ==, 1);
item = g_list_model_get_item (model, 0);
g_assert_nonnull (item);
item = g_list_model_get_item (model, G_MAXUINT);
g_assert_null (item);
g_object_unref (store);
}
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
g_test_init (&argc, &argv, NULL); g_test_init (&argc, &argv, NULL);
...@@ -809,6 +837,7 @@ int main (int argc, char *argv[]) ...@@ -809,6 +837,7 @@ int main (int argc, char *argv[])
test_store_get_item_cache); test_store_get_item_cache);
g_test_add_func ("/glistmodel/store/items-changed", g_test_add_func ("/glistmodel/store/items-changed",
test_store_signal_items_changed); test_store_signal_items_changed);
g_test_add_func ("/glistmodel/store/past-end", test_store_past_end);
return g_test_run (); return g_test_run ();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment