Skip to content

Commit

Permalink
Avoid using out of range value in wxSpinCtrl with inversed range.
Browse files Browse the repository at this point in the history
In wxMSW it is possible that minimal allowed value is greater than maximal
allowed one and the native control works correctly in this case, however
wxSpinCtrl set m_oldValue to an invalid value which could result in an
infinite recursion if SetRange() was called from the wxEVT_SPINCTRL event
handler.

For example, if the control value was initially 0 and the event handler called
SetRange(1, 0), it would result setting the value to 1 because it was less
than the minimum, resulting in another call to the event handler which would
now set the value to 0 because it was more than the maximum resulting in
another call to the event handler and so forth.

Fix this by ensuring that the value lies between minimal and maximal values,
whatever is their relative order.
  • Loading branch information
vadz committed May 20, 2015
1 parent ba107a9 commit 5f8ac45
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/msw/spinctrl.cpp
Expand Up @@ -544,10 +544,20 @@ void wxSpinCtrl::SetRange(int minVal, int maxVal)
// Manually adjust the old value to avoid an event being sent from
// NormalizeValue() called from inside the base class SetRange() as we're
// not supposed to generate any events from here.
if ( m_oldValue < minVal )
m_oldValue = minVal;
else if ( m_oldValue > maxVal )
m_oldValue = maxVal;
if ( minVal <= maxVal )
{
if ( m_oldValue < minVal )
m_oldValue = minVal;
else if ( m_oldValue > maxVal )
m_oldValue = maxVal;
}
else // reversed range
{
if ( m_oldValue > minVal )
m_oldValue = minVal;
else if ( m_oldValue < maxVal )
m_oldValue = maxVal;
}

wxSpinButton::SetRange(minVal, maxVal);

Expand Down

0 comments on commit 5f8ac45

Please sign in to comment.