QBrush: be more robust in detach()

If detach() was called with a newStyle corresponding to a gradient,
but with d->style not a gradient, it would execute an invalid cast
and read invalid memory.

The reason this has not been seen in practice is that a non-gradient
brush instance can currently never become a gradient one. But that
may change when someone adds an operator=(QGradient), so in the
interest of robust code, add a check to verify the old style was a
gradient before accessing the corresponding member.

Change-Id: I216a144d31a9ed7145bcd829f3ae5f44a41672db
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
bb10
Marc Mutz 2014-08-29 22:27:00 +02:00
parent 39b32f0874
commit 1adc586abd
1 changed files with 10 additions and 2 deletions

View File

@ -596,8 +596,16 @@ void QBrush::detach(Qt::BrushStyle newStyle)
case Qt::RadialGradientPattern:
case Qt::ConicalGradientPattern:
x.reset(new QGradientBrushData);
static_cast<QGradientBrushData *>(x.data())->gradient =
static_cast<QGradientBrushData *>(d.data())->gradient;
switch (d->style) {
case Qt::LinearGradientPattern:
case Qt::RadialGradientPattern:
case Qt::ConicalGradientPattern:
static_cast<QGradientBrushData *>(x.data())->gradient =
static_cast<QGradientBrushData *>(d.data())->gradient;
break;
default:
break;
}
break;
default:
x.reset(new QBrushData);