D27965: [KPasswdServer] replace foreach with range/index-based for

David Faure noreply at phabricator.kde.org
Wed Mar 11 21:47:50 GMT 2020


dfaure added a comment.


  In D27965#625676 <https://phabricator.kde.org/D27965#625676>, @ahmadsamir wrote:
  
  > In D27965#625526 <https://phabricator.kde.org/D27965#625526>, @apol wrote:
  >
  > > Having the iterated value change under the hood will eventually break. I'd suggest preferring QList::erase to QList::removeOne.
  >
  >
  > 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.

REPOSITORY
  R241 KIO

BRANCH
  l-kpasswdserver (branched from master)

REVISION DETAIL
  https://phabricator.kde.org/D27965

To: ahmadsamir, #frameworks, dfaure, meven
Cc: apol, kde-frameworks-devel, LeGast00n, cblack, GB_2, michaelh, ngraham, bruns
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20200311/bb5cca8e/attachment-0001.html>


More information about the Kde-frameworks-devel mailing list