]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
- fix a crash in checkboxtree.c where pressing pgup/pgdown
authormlichvar <mlichvar>
Fri, 15 Sep 2006 13:25:19 +0000 (13:25 +0000)
committermlichvar <mlichvar>
Fri, 15 Sep 2006 13:25:19 +0000 (13:25 +0000)
  on a checkboxtree with less items than its height would
  cause segmentation violation (#165347)

checkboxtree.c

index f862db69df7641600b0c6a2df008af00dbb51e55..262e1d2680fa3415f8e4de28ed91b2951d0f79fa 100644 (file)
@@ -536,6 +536,18 @@ static void ctDestroy(newtComponent co) {
     free(co);
 }
 
+static void ctEnsureLimits( struct CheckboxTree *ct ) {
+    struct items **listEnd = ct->flatList + ct->flatCount - 1;
+    if (ct->firstItem < ct->flatList)
+        ct->firstItem = ct->flatList;
+    if (ct->currItem < ct->flatList)
+        ct->currItem = ct->flatList;
+    if (ct->firstItem > listEnd) {
+        ct->firstItem = listEnd;
+        ct->currItem = listEnd;
+    }
+}
+
 struct eventResult ctEvent(newtComponent co, struct event ev) {
     struct CheckboxTree * ct = co->data;
     struct eventResult er;
@@ -647,6 +659,7 @@ struct eventResult ctEvent(newtComponent co, struct event ev) {
                ct->currItem -= co->height;
                ct->firstItem -= co->height;
            }
+           ctEnsureLimits( ct );
 
            ctDraw(co);
            if(co->callback) co->callback(co, co->callbackData);
@@ -663,6 +676,7 @@ struct eventResult ctEvent(newtComponent co, struct event ev) {
                ct->currItem += co->height;
                ct->firstItem += co->height;
            }
+           ctEnsureLimits( ct );
 
            ctDraw(co);
            if(co->callback) co->callback(co, co->callbackData);