Skip to content

Commit

Permalink
Avoid undefined behaviour with signed integer overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Mercier committed Feb 14, 2019
1 parent 0d178aa commit 3ef1605
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/gui/editorwidgets/qgsrangewidgetwrapper.cpp
Expand Up @@ -144,12 +144,12 @@ void QgsRangeWidgetWrapper::initWidget( QWidget *editor )
int minval = min.toInt(); int minval = min.toInt();
if ( allowNull ) if ( allowNull )
{ {
int stepval = step.isValid() ? step.toInt() : 1; uint stepval = step.isValid() ? step.toUInt() : 1;
int newMinval = minval - stepval;
// make sure there is room for a new value (i.e. signed integer does not overflow) // make sure there is room for a new value (i.e. signed integer does not overflow)
if ( newMinval < minval ) int minvalOverflow = uint( minval ) - stepval;
if ( minvalOverflow < minval )
{ {
minval = newMinval; minval = minvalOverflow;
} }
mIntSpinBox->setValue( minval ); mIntSpinBox->setValue( minval );
QgsSpinBox *intSpinBox( qobject_cast<QgsSpinBox *>( mIntSpinBox ) ); QgsSpinBox *intSpinBox( qobject_cast<QgsSpinBox *>( mIntSpinBox ) );
Expand Down

0 comments on commit 3ef1605

Please sign in to comment.