Opened 4 years ago

Closed 4 years ago

#11808 closed defect (fixed)

wxList::insert() return value is wrong

Reported by: aldimond Owned by:
Priority: normal Milestone: 2.9.1
Component: base Version: stable-latest
Keywords: Cc:
Blocked By: Blocking:
Patch: no

Description

It returns the iterator you passed in instead of one to the new item.

I'm looking at 2.8 branch, current SVN. At include/wx/list.h:1043 is:

return itprev--;

That decrements the iterator then returns old value. I thought using --itprev would work but in the case where you're inserting at the end of the list a totally different node is returned. It appears that the iterator types' operator-- doesn't work for this case. So that would have to be special-cased I guess.

It's probably not a good idea to fix this in the 2.8 branch, as it might break existing code depending on the old, incorrect behavior. I don't know if it's a problem in 2.9.

Change History (2)

comment:1 Changed 4 years ago by vadz

  • Milestone set to 2.9.1
  • Status changed from new to confirmed
  • Version changed from 2.8-svn to 2.9-svn

Thanks for reporting the bug!

The code in 2.9 looks the same and is still wrong, I have no idea what was the intention here but it doesn't make any sense to use postfix operation on a value being returned.

We need to fix this (for !wxUSE_STL) and add unit tests checking that it really does behave as expected.

comment:2 Changed 4 years ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [63943]) Fix return value of wxList::insert() in non-STL builds.

The returned value was the same as the iterator that was passed in which could
even be invalid when appending.

Fix the wrong use of postfix decrement instead of prefix one and handle the
case of appending correctly.

Closes #11808.

Note: See TracTickets for help on using tickets.