Bugs in KComboBox

Waldo Bastian bastian at kde.org
Thu Nov 11 15:48:54 GMT 2004


On Thursday 11 November 2004 16:40, Andrew Coles wrote:
> Whilst reading through KComboBox.cpp I spotted what I think look like a few
> bugs.  Wanting to be sure that my understanding is correct, and not being
> arrogant enough to risk breaking lots of existing code (given it's used all
> over the place), I've detailed them here along with my fixes; if they're
> OKed I'll commit.
>
> 1) From KHistoryCombo::addToHistory, line 450
>
> This code will, if I understand correctly, will only remove half the
> entries in the list, as the call to removeItem(i) will shuffle the indices
> for the rest of the entries backwards one.
>
> for ( int i = 0; i < count(); i++ ) {
>  if ( text( i ) == item ) {
>   if ( !wasCurrent )
>    wasCurrent = ( i == currentItem() );
>   removeItem( i );
>  }
> }
>
> Solution - ditch the call to removeItem(i) and call clear() after the for
> loop has completed.

That would ignore the if ( text( i ) == item ) test.
Although I agree that this can use improvement, I doubt the current version 
will cause much problems because if duplicates are indeed disabled the test 
condition will only be true once anyway.

> 2) From KHistoryCombo::removeFromHistory, line 494
>
> This code will only remove the first of two adjacent matches if they exist,
> leaving the second in the list - again, the remaining indices are shuffled
> backwards one for each removal.
>
> for ( int i = 0; i < count(); i++ ) {
>  while ( item == text( i ) ) {
>   removed = true;
>   removeItem( i );
>  }
> }

I think this one actually does it better, it will not increment the index as 
long as it find matches, it's still wrong in the sense that it doesn't check 
(i < count()) in the while loop.

Cheers,
Waldo
-- 
bastian at kde.org   |   Free Novell Linux Desktop 9 Evaluation Download
bastian at suse.com  |   http://www.novell.com/products/desktop/eval.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20041111/fb3fb626/attachment.sig>


More information about the kde-core-devel mailing list