diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-10-02 13:06:04 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-10-10 08:23:31 +0000 |
commit | f864a62ccd639c2f9b255fdf9927973b4a678e7f (patch) | |
tree | ffdedbe022ff59a32dc3c569b848e1dd81b36067 /src/gui/image/qimage.cpp | |
parent | 9436e3c315420c7ebfb36628e6bf388c780bf0ca (diff) |
Add missing null checks after detach
A few places we didn't check if detach() succeeded including
in reinterpretAsFormat(), where it can be undone.
Task-number: QTBUG-70785
Change-Id: Ibcc8e26e2961f6288eb7a045ae1cb28e59213a49
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src/gui/image/qimage.cpp')
-rw-r--r-- | src/gui/image/qimage.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 8a4c6b7fda..636cacfb9c 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -1454,7 +1454,8 @@ void QImage::setDevicePixelRatio(qreal scaleFactor) return; detach(); - d->devicePixelRatio = scaleFactor; + if (d) + d->devicePixelRatio = scaleFactor; } /*! @@ -2240,8 +2241,15 @@ bool QImage::reinterpretAsFormat(Format format) return true; if (qt_depthForFormat(format) != qt_depthForFormat(d->format)) return false; - if (!isDetached()) // Detach only if shared, not for read-only data. + if (!isDetached()) { // Detach only if shared, not for read-only data. + QImageData *oldD = d; detach(); + // In case detach() ran out of memory + if (!d) { + d = oldD; + return false; + } + } d->format = format; return true; @@ -3288,6 +3296,8 @@ void QImage::mirrored_inplace(bool horizontal, bool vertical) return; detach(); + if (!d) + return; if (!d->own_data) *this = copy(); @@ -3440,6 +3450,8 @@ void QImage::rgbSwapped_inplace() return; detach(); + if (!d) + return; if (!d->own_data) *this = copy(); |