Skip to content

Commit ef1634c

Browse files
Hugo Merciernyalldawson
Hugo Mercier
authored andcommitted
Fix "Allow null" in range widget (fixes #20831)
By default a range widget is built with a minimum value set to the minimal integer that is possible to represent. When "allow null" is enabled, a new value (minvalue - 1) is inserted. With the default value, we then had an integer overflow. (cherry picked from commit eb5a336)
1 parent 9abcd0e commit ef1634c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/gui/editorwidgets/qgsrangewidgetwrapper.cpp

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

0 commit comments

Comments
 (0)