From d8a0dcb11e92d3237f5f4e90a4916df518bdc53d Mon Sep 17 00:00:00 2001
From: Matthias Clasen <mclasen@redhat.com>
Date: Sun, 6 Jan 2019 14:17:30 -0500
Subject: [PATCH 441/682] 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
---
 gio/gliststore.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gio/gliststore.c b/gio/gliststore.c
index ae8e2c1d8..8d87159d5 100644
--- a/gio/gliststore.c
+++ b/gio/gliststore.c
@@ -181,9 +181,9 @@ g_list_store_get_item (GListModel *list,
 
   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);
-      else if (store->last_position == position - 1)
+      else if (position > 0 && store->last_position == position - 1)
         it = g_sequence_iter_next (store->last_iter);
       else if (store->last_position == position)
         it = store->last_iter;
-- 
2.19.1

