[PATCH libreoffice-4-0] fdo#62094 - fix infinite loop in radio button group iteratio...

Michael Meeks (via Code Review) gerrit at gerrit.libreoffice.org
Wed Mar 27 09:48:53 PDT 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3095

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/95/3095/1

fdo#62094 - fix infinite loop in radio button group iteration.

Simplify the code too - we copy the vector anyway, so reversing it
should be cheap.

Change-Id: Ie655ba3044c7e0dd5a15b0e839a3712a32a1e298
---
M vcl/source/window/dlgctrl.cxx
1 file changed, 12 insertions(+), 37 deletions(-)



diff --git a/vcl/source/window/dlgctrl.cxx b/vcl/source/window/dlgctrl.cxx
index 6c481da..62f7f75 100644
--- a/vcl/source/window/dlgctrl.cxx
+++ b/vcl/source/window/dlgctrl.cxx
@@ -533,39 +533,14 @@
         return (pWindow && isVisibleInLayout(pWindow) && isEnabledInLayout(pWindow) && pWindow->IsInputEnabled());
     }
 
-    bool backInGroup(std::vector<RadioButton*>::reverse_iterator aRevStart, std::vector<RadioButton*> &rGroup)
-    {
-        std::vector<RadioButton*>::reverse_iterator aI(aRevStart);
-        while (aI != rGroup.rend())
-        {
-            Window *pWindow = *aI;
-
-            if (isSuitableDestination(pWindow))
-            {
-                pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_BACKWARD );
-                return true;
-            }
-        }
-
-        aI = rGroup.rbegin();
-        while (aI != aRevStart)
-        {
-            Window *pWindow = *aI;
-
-            if (isSuitableDestination(pWindow))
-            {
-                pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_BACKWARD );
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    bool forwardInGroup(std::vector<RadioButton*>::iterator aStart, std::vector<RadioButton*> &rGroup)
+    bool focusNextInGroup(std::vector<RadioButton*>::iterator aStart, std::vector<RadioButton*> &rGroup)
     {
         std::vector<RadioButton*>::iterator aI(aStart);
-        while (++aI != rGroup.end())
+
+        if (aStart != rGroup.end())
+            ++aI;
+
+        for (; aI != rGroup.end(); ++aI)
         {
             Window *pWindow = *aI;
 
@@ -576,8 +551,7 @@
             }
         }
 
-        aI = rGroup.begin();
-        while (aI != aStart)
+        for (aI = rGroup.begin(); aI != aStart; ++aI)
         {
             Window *pWindow = *aI;
 
@@ -586,6 +560,7 @@
                 pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_FORWARD );
                 return true;
             }
+            aI++;
         }
 
         return false;
@@ -598,14 +573,14 @@
         if (aGroup.size() == 1) //only one button in group
             return false;
 
+        if (bBackward)
+            std::reverse(aGroup.begin(), aGroup.end());
+
         std::vector<RadioButton*>::iterator aStart(std::find(aGroup.begin(), aGroup.end(), pSourceWindow));
 
         assert(aStart != aGroup.end());
 
-        if (bBackward)
-            return backInGroup(std::vector<RadioButton*>::reverse_iterator(aStart), aGroup);
-        else
-            return forwardInGroup(aStart, aGroup);
+        return focusNextInGroup(aStart, aGroup);
     }
 }
 

-- 
To view, visit https://gerrit.libreoffice.org/3095
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie655ba3044c7e0dd5a15b0e839a3712a32a1e298
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-4-0
Gerrit-Owner: Michael Meeks <michael.meeks at suse.com>



More information about the LibreOffice mailing list