sc/source/ui/unoobj/viewuno.cxx | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
New commits: commit 6f69c445719e7c100e2669dae1afc0b9a44267c5 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Thu Jan 6 18:38:58 2022 +0300 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Mon Jan 10 14:56:55 2022 +0100 tdf#146617: iterators may be invalidated during handler call ... when the handler decides to remove itself from listeners. Change-Id: I1d5fe802f50d284bf70d747edaff0a19852c5a7d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128054 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> (cherry picked from commit e9dce4e8cbea04d6c6636a45f5a172e986714409) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128074 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> (cherry picked from commit 6d8b019f8f72d9802d86ab0414c909db04fdc912) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128160 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sc/source/ui/unoobj/viewuno.cxx b/sc/source/ui/unoobj/viewuno.cxx index a758a9054600..2085d217a1f3 100644 --- a/sc/source/ui/unoobj/viewuno.cxx +++ b/sc/source/ui/unoobj/viewuno.cxx @@ -545,16 +545,16 @@ void ScTabViewObj::SheetChanged( bool bSameTabButMoved ) uno::Reference< uno::XInterface > xSource(xView, uno::UNO_QUERY); aEvent.Source = xSource; aEvent.ActiveSheet = new ScTableSheetObj(pDocSh, rViewData.GetTabNo()); - for (auto it = aActivationListeners.begin(); it != aActivationListeners.end(); ) + // Listener's handler may remove it from the listeners list + for (size_t i = aActivationListeners.size(); i > 0; --i) { try { - (*it)->activeSpreadsheetChanged( aEvent ); - ++it; + aActivationListeners[i - 1]->activeSpreadsheetChanged( aEvent ); } catch( uno::Exception& ) { - it = aActivationListeners.erase( it); + aActivationListeners.erase(aActivationListeners.begin() + (i - 1)); } } } @@ -1150,17 +1150,17 @@ bool ScTabViewObj::MousePressed( const awt::MouseEvent& e ) aMouseEvent.Target = xTarget; aMouseEvent.Modifiers = e.Modifiers; - for (auto it = aMouseClickHandlers.begin(); it != aMouseClickHandlers.end(); ) + // Listener's handler may remove it from the listeners list + for (size_t i = aMouseClickHandlers.size(); i > 0; --i) { try { - if (!(*it)->mousePressed( aMouseEvent )) + if (!aMouseClickHandlers[i - 1]->mousePressed(aMouseEvent)) bReturn = true; - ++it; } catch ( uno::Exception& ) { - it = aMouseClickHandlers.erase(it); + aMouseClickHandlers.erase(aMouseClickHandlers.begin() + (i - 1)); } } } @@ -1260,17 +1260,17 @@ bool ScTabViewObj::MouseReleased( const awt::MouseEvent& e ) aMouseEvent.Target = xTarget; aMouseEvent.Modifiers = e.Modifiers; - for (auto it = aMouseClickHandlers.begin(); it != aMouseClickHandlers.end(); ) + // Listener's handler may remove it from the listeners list + for (size_t i = aMouseClickHandlers.size(); i > 0; --i) { try { - if (!(*it)->mouseReleased( aMouseEvent )) + if (!aMouseClickHandlers[i - 1]->mouseReleased( aMouseEvent )) bReturn = true; - ++it; } catch ( uno::Exception& ) { - it = aMouseClickHandlers.erase(it); + aMouseClickHandlers.erase(aMouseClickHandlers.begin() + (i - 1)); } } }