Skip to content

Commit

Permalink
QgsColorRampButton::setColorRamp(): fix null pointer dereference
Browse files Browse the repository at this point in the history
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 996d812
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
19 changes: 8 additions & 11 deletions src/gui/qgscolorrampbutton.cpp
Expand Up @@ -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 )
Expand Down
1 change: 0 additions & 1 deletion src/gui/qgscolorrampbutton.h
Expand Up @@ -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;

Expand Down

0 comments on commit 996d812

Please sign in to comment.