Kaydet (Commit) 1107e4d7 authored tarafından Michael Meeks's avatar Michael Meeks Kaydeden (comit) Fridrich Strba

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
Reviewed-on: https://gerrit.libreoffice.org/3095Reviewed-by: 's avatarFridrich Strba <fridrich@documentfoundation.org>
Tested-by: 's avatarFridrich Strba <fridrich@documentfoundation.org>
üst f8ca5b1b
...@@ -533,39 +533,14 @@ namespace ...@@ -533,39 +533,14 @@ namespace
return (pWindow && isVisibleInLayout(pWindow) && isEnabledInLayout(pWindow) && pWindow->IsInputEnabled()); return (pWindow && isVisibleInLayout(pWindow) && isEnabledInLayout(pWindow) && pWindow->IsInputEnabled());
} }
bool backInGroup(std::vector<RadioButton*>::reverse_iterator aRevStart, std::vector<RadioButton*> &rGroup) bool focusNextInGroup(std::vector<RadioButton*>::iterator aStart, std::vector<RadioButton*> &rGroup)
{ {
std::vector<RadioButton*>::reverse_iterator aI(aRevStart); std::vector<RadioButton*>::iterator aI(aStart);
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; if (aStart != rGroup.end())
} ++aI;
bool forwardInGroup(std::vector<RadioButton*>::iterator aStart, std::vector<RadioButton*> &rGroup) for (; aI != rGroup.end(); ++aI)
{
std::vector<RadioButton*>::iterator aI(aStart);
while (++aI != rGroup.end())
{ {
Window *pWindow = *aI; Window *pWindow = *aI;
...@@ -576,8 +551,7 @@ namespace ...@@ -576,8 +551,7 @@ namespace
} }
} }
aI = rGroup.begin(); for (aI = rGroup.begin(); aI != aStart; ++aI)
while (aI != aStart)
{ {
Window *pWindow = *aI; Window *pWindow = *aI;
...@@ -598,14 +572,14 @@ namespace ...@@ -598,14 +572,14 @@ namespace
if (aGroup.size() == 1) //only one button in group if (aGroup.size() == 1) //only one button in group
return false; return false;
if (bBackward)
std::reverse(aGroup.begin(), aGroup.end());
std::vector<RadioButton*>::iterator aStart(std::find(aGroup.begin(), aGroup.end(), pSourceWindow)); std::vector<RadioButton*>::iterator aStart(std::find(aGroup.begin(), aGroup.end(), pSourceWindow));
assert(aStart != aGroup.end()); assert(aStart != aGroup.end());
if (bBackward) return focusNextInGroup(aStart, aGroup);
return backInGroup(std::vector<RadioButton*>::reverse_iterator(aStart), aGroup);
else
return forwardInGroup(aStart, aGroup);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment