summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2022-01-06 18:38:58 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2022-01-06 20:44:42 +0100
commite9dce4e8cbea04d6c6636a45f5a172e986714409 (patch)
tree03532227ac07bb4b86ec3c5487022cc752b71e97 /sc/source
parent568293d7ce6d96ba71ae8c2d591b6cf237e31db1 (diff)
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.kaganski@collabora.com>
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/ui/unoobj/viewuno.cxx24
1 files changed, 12 insertions, 12 deletions
diff --git a/sc/source/ui/unoobj/viewuno.cxx b/sc/source/ui/unoobj/viewuno.cxx
index 7ca9df64e88d..e933830534d3 100644
--- a/sc/source/ui/unoobj/viewuno.cxx
+++ b/sc/source/ui/unoobj/viewuno.cxx
@@ -544,16 +544,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));
}
}
}
@@ -1149,17 +1149,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));
}
}
}
@@ -1256,17 +1256,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));
}
}
}