RE: [Plib-devel] [PATCH] puListBox.cxx: don't crash with empty li st + setTopItem(0)
Brought to you by:
sjbaker
From: Fay J. F Dr C. U. AFSEO/SK <joh...@eg...> - 2006-04-27 16:14:14
|
Melchior, That is a good find, but I'm a little concerned about the fix. I would prefer the following code: puListBox.cxx:74 void puListBox::setTopItem( int item_index ) { top = item_index ; + if ( top > num-1 ) + top = num-1; if ( top < 0 ) top = 0 ; - else if ( top > num-1 ) - top = num-1; puPostRefresh () ; } That will handle your case and will also handle a case in which "item_index" is greater than the number of entries. You might wind up crashing anyway, though. I appear to be CVS-challenged again. Would somebody else please put this in for us? John F. Fay Technical Fellow, Jacobs/Sverdrup TEAS Group 850-729-6330 joh...@eg... -----Original Message----- From: pli...@li... [mailto:pli...@li...] On Behalf Of Melchior FRANZ Sent: Tuesday, April 18, 2006 10:19 AM To: pli...@li... Subject: [Plib-devel] [PATCH] puListBox.cxx: don't crash with empty list + setTopItem(0) The attached patch makes sure that plib doesn't crash if a puListBox was created with an empty list and the top item is set to 0 (which happens on "up" arrow in puList, for example). In this case else if ( top > num-1 ) evaluates to (0 > -1) -> true, which sets top = num-1; -> -1 which accesses invalid memory with list[-1] in puListBox.cxx:135. m. |