list store: Fix overflow issues

Check for over- and underflow when manipulating positions.

This makes the sequence
  g_list_model_get_item (store, 0);
  g_list_model_get_item (store, -1u);
return NULL for the second call, as it should.

Closes: #1639
This commit is contained in:
Matthias Clasen 2019-01-06 14:17:30 -05:00
parent 471153fb20
commit d8a0dcb11e

View File

@ -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;