sc/source/ui/view/gridwin.cxx |   21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

New commits:
commit e8998c6d12773e7b3196ea151c4f617ec5dab1a4
Author:     Vasily Melenchuk <vasily.melenc...@cib.de>
AuthorDate: Thu Sep 30 14:10:12 2021 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Fri Oct 1 16:35:49 2021 +0200

    sc: colorfilter dangling pointer fixed
    
    Upper call to aParam.RemoveAllEntriesByField can invalidate
    pEntry, making further calls to pEntry->SetQueryBy* illegal.
    
    Anyway at this branch we are disabling color filter, so this
    is not required.
    
    Change-Id: Ia595649975b659d28056ba3f3658c306e63088f5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122822
    Tested-by: Jenkins
    Reviewed-by: Vasily Melenchuk <vasily.melenc...@cib.de>
    (cherry picked from commit bf4cb13c7b3b57980d8e052c1b06afc3f21b96f2)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122865
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 9edc1d29af64..a0f854a6394f 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -970,6 +970,7 @@ void ScGridWindow::UpdateAutoFilterFromMenu(AutoFilterMode 
eMode)
                 if (nSelected == nActive)
                 {
                     aParam.RemoveAllEntriesByField(rPos.Col());
+                    pEntry = nullptr;   // invalidated by 
RemoveAllEntriesByField call
 
                     // tdf#46184 reset filter options to default values
                     aParam.eSearchType = utl::SearchParam::SearchType::Normal;
@@ -977,16 +978,18 @@ void 
ScGridWindow::UpdateAutoFilterFromMenu(AutoFilterMode eMode)
                     aParam.bDuplicate = true;
                     aParam.bInplace = true;
                 }
-
-                // Get selected color from set
-                std::set<Color>::iterator it = aColors.begin();
-                std::advance(it, nSelected - 1);
-                Color selectedColor = *it;
-
-                if (eMode == AutoFilterMode::TextColor)
-                    pEntry->SetQueryByTextColor(selectedColor);
                 else
-                    pEntry->SetQueryByBackgroundColor(selectedColor);
+                {
+                    // Get selected color from set
+                    std::set<Color>::iterator it = aColors.begin();
+                    std::advance(it, nSelected - 1);
+                    Color selectedColor = *it;
+
+                    if (eMode == AutoFilterMode::TextColor)
+                        pEntry->SetQueryByTextColor(selectedColor);
+                    else
+                        pEntry->SetQueryByBackgroundColor(selectedColor);
+                }
             }
 
             break;

Reply via email to