Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
What should happen if QStringList erase function is fed a bad iterator?
I have a QStringList. Another function is generating an iterator that is passed to the erase function:
there is a good chance that sometimes aQstringlist will actually be of size zero, and the iterator is the off-the-end iterator (i.e. @aQstringlist.end() @).
The documentation doesn't specify what the erase function would do in such a case; I am seeing intermittent segFaults that might indicate unspecified behaviour, or just being (un)lucky. Does anyone know what the official verdict is on what erase does in such a case?
You are trying to delete a non-existant object thus the segmentation fault.
Are you sure your design is right if one function can create something that makes the other crash ?
At the very least, you should check that there's something to erase.
I have no idea if the design is right; it's uncommented, undocumented and inherited, and the original author has been locked out of the repository in self-defence :p
Sounds like the QStringList erase function doesn't do any sanity-checking of its own then? That's fine, it's utterly reasonable; it's just not clear from the 4.8 documentation that this is the case :) I wasn't really expecting it to, but it's worth checking.
Current thinking is that the original author meant to pass TWO iterators to erase; the second one being the end() iterator, such that if the first iterator is also off the end, nothing happens.
Then this screams for refactoring !
I'm very old, so I don't refactor; I just rewrite :p
Passed the second iterator (end) as well, no more segFaults.
Sometimes it's the only thing to do...
Great you found out !