From: mlichvar Date: Fri, 15 Sep 2006 13:25:19 +0000 (+0000) Subject: - fix a crash in checkboxtree.c where pressing pgup/pgdown X-Git-Tag: r0-52-3~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=21f6373f024eadcb9818b6e1a2961c9cda538241;p=thirdparty%2Fnewt.git - fix a crash in checkboxtree.c where pressing pgup/pgdown on a checkboxtree with less items than its height would cause segmentation violation (#165347) --- diff --git a/checkboxtree.c b/checkboxtree.c index f862db6..262e1d2 100644 --- a/checkboxtree.c +++ b/checkboxtree.c @@ -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);