Skip to content

Commit ed45181

Browse files
author
Hugo Mercier
authored
Merge pull request #9064 from mhugo/fix_20831
Avoid undefined behaviour with signed integer overflow
2 parents e953141 + 5609f4a commit ed45181

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/gui/editorwidgets/qgsrangewidgetwrapper.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ void QgsRangeWidgetWrapper::initWidget( QWidget *editor )
145145
int minval = min.toInt();
146146
if ( allowNull )
147147
{
148-
int stepval = step.isValid() ? step.toInt() : 1;
149-
int newMinval = minval - stepval;
148+
uint stepval = step.isValid() ? step.toUInt() : 1;
150149
// make sure there is room for a new value (i.e. signed integer does not overflow)
151-
if ( newMinval < minval )
150+
int minvalOverflow = uint( minval ) - stepval;
151+
if ( minvalOverflow < minval )
152152
{
153-
minval = newMinval;
153+
minval = minvalOverflow;
154154
}
155155
mIntSpinBox->setValue( minval );
156156
QgsSpinBox *intSpinBox( qobject_cast<QgsSpinBox *>( mIntSpinBox ) );

0 commit comments

Comments
 (0)