Archived issue #0027367
The last element remove crash during NCollection_List iteration
Description
The NCollection_List iteration crashes if the list last element is removed during the iteration.
Steps to reproduce
NCollection_List<Standard_Integer> aList;
aList.Prepend(0);
aList.Prepend(1);
NCollection_List<Standard_Integer>::Iterator aIt(aList);
for (; aIt.More(); aIt.Next())
{
if (aIt.Value() == 0)
{
aList.Remove(aIt);
}
}
aList.Prepend(0);
aList.Prepend(1);
NCollection_List<Standard_Integer>::Iterator aIt(aList);
for (; aIt.More(); aIt.Next())
{
if (aIt.Value() == 0)
{
aList.Remove(aIt);
}
}
Public activity
2 archived notes
Participants are labeled by their role within this record.
The cycle given in Steps to Reproduce is organized in incorrect way. When element is removed from the list, iterator is modified to point to the next element, and Next() should not be called. If the cycle is corrected, the problem will not appear any more.
Note that this is not specific to lists, but relevant for iteration by any collection.
The immediate reason of exception is that method Next() causes access violation if iterator is in stop state (More() returns False). The protection could be added, however it may affect performance and would be rather useless, letting the problem to remain unnoticed.
Alexander, please confirm that you agree with my conclusion (you might need to correct the code where you found this issue), so that I could close the issue.
Note that this is not specific to lists, but relevant for iteration by any collection.
The immediate reason of exception is that method Next() causes access violation if iterator is in stop state (More() returns False). The protection could be added, however it may affect performance and would be rather useless, letting the problem to remain unnoticed.
Alexander, please confirm that you agree with my conclusion (you might need to correct the code where you found this issue), so that I could close the issue.
The conclusion is acceptable for me.
Please process the bug by a way that is right in your opinion.
Please process the bug by a way that is right in your opinion.