Skip to content
Permalink
Browse files

QgsColorRampButton::setColorRamp(): fix null pointer dereference

when colorramp argument was nullptr, which could occur when called from
QgsColorRampButton::setToNull()
The logic to detect if the colorramp was changed was convoluted and
wrong too.

Spotted by cppcheck
  • Loading branch information
rouault authored and nyalldawson committed May 19, 2020
1 parent 146e1e2 commit 996d812fee1b91ab40271f3fee35347171d9d046
Showing with 8 additions and 12 deletions.
  1. +8 −11 src/gui/qgscolorrampbutton.cpp
  2. +0 −1 src/gui/qgscolorrampbutton.h
@@ -467,20 +467,17 @@ void QgsColorRampButton::resizeEvent( QResizeEvent *event )

void QgsColorRampButton::setColorRamp( QgsColorRamp *colorramp )
{
QgsColorRamp *oldColorRamp = mColorRamp;
mColorRamp = colorramp->clone();
if ( colorramp == mColorRamp )
return;

delete mColorRamp;
mColorRamp = colorramp ? colorramp->clone() : nullptr;

// handle when initially set color is same as default (Qt::black); consider it a color change
if ( ( oldColorRamp != mColorRamp ) || !mColorRampSet )
setButtonBackground();
if ( isEnabled() )
{
setButtonBackground();
if ( isEnabled() )
{
emit colorRampChanged();
}
emit colorRampChanged();
}
delete oldColorRamp;
mColorRampSet = true;
}

void QgsColorRampButton::setColorRampFromName( const QString &name )
@@ -291,7 +291,6 @@ class GUI_EXPORT QgsColorRampButton : public QToolButton
QgsColorRamp *mDefaultColorRamp = nullptr;
QString mContext;
bool mAcceptLiveUpdates = true;
bool mColorRampSet = false;
bool mShowRandomColorRamp = false;
bool mShowNull = false;

0 comments on commit 996d812

Please sign in to comment.
You can’t perform that action at this time.