make && ctest
Details
- Reviewers
dfaure meven - Group Reviewers
Frameworks - Commits
- R241:018f223692de: [KPasswdServer] replace foreach with range/index-based for
Diff Detail
- Repository
- R241 KIO
- Lint
Automatic diff as part of commit; lint not applicable. - Unit
Automatic diff as part of commit; unit tests not applicable.
Those modified the list as they iterated through the list : authList->removeOne(current);
Actually, the code also uses 'delete current', now if there's another instance of that AuthInfoContainer* in authList, on a next iteration accessing the pointer "current" would be invalid as the object it had pointed to has been already delete'ed... I think removeAll() would be a better fit; WDYT?
authList does not contain duplicates. Otherwise the current code would already have the problem you're mentioning.
So I see no reason to protect against that case.
erase sounds much safer than removeOne which has unclear consequences on the iterators.
- I missed one foreach before
- Use erase() instead of remove(), safer to work on QList iterators
src/kpasswdserver/kpasswdserver.cpp | ||
---|---|---|
201 | I wonder why the whole method isn't const | |
648 | This is not the way to use erase(). It invalidates the iterator... The proper way is it = authList->erase(it); and doing ++it at the end of the for loop, not in the 3rd part of the for() line, since we don't want ++it after it=erase(it). | |
680–681 | same problem here. | |
716 | (this one is fine, there's a "break;" below) |