summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qimage.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-12-04 09:58:43 +0100
committerLiang Qi <liang.qi@qt.io>2018-12-04 09:58:43 +0100
commit5d5c00c67682bce105197b659687fd1fee8f60cf (patch)
tree686e41dc3ea121235fb73afb9157ed603f1bfeff /src/gui/image/qimage.cpp
parentf213e818f03d35cb82e3daf187415197fd156f8e (diff)
parentb82559244e2dc03f1ceff66bb67630df4300dc7c (diff)
Merge remote-tracking branch 'origin/5.12' into dev
Conflicts: src/gui/painting/qdrawhelper.cpp Change-Id: I4916e07b635e1d3830e9b46ef7914f99bec3098e
Diffstat (limited to 'src/gui/image/qimage.cpp')
-rw-r--r--src/gui/image/qimage.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index 0105f1decd..da963adae6 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -149,7 +149,10 @@ QImageData * QImageData::create(const QSize &size, QImage::Format format)
d->bytes_per_line = params.bytesPerLine;
d->nbytes = params.totalSize;
- d->data = (uchar *)malloc(d->nbytes);
+ if (depth == 64)
+ d->data = (uchar *)new (std::nothrow) quint64[d->nbytes / sizeof(quint64)];
+ else // nbytes is known to already be a multipla of 4:
+ d->data = (uchar *)new (std::nothrow) quint32[d->nbytes / sizeof(quint32)];
if (!d->data)
return nullptr;
@@ -165,8 +168,13 @@ QImageData::~QImageData()
if (is_cached)
QImagePixmapCleanupHooks::executeImageHooks((((qint64) ser_no) << 32) | ((qint64) detach_no));
delete paintEngine;
- if (data && own_data)
- free(data);
+ if (data && own_data) {
+ // Casting to avoid being theoretically UB:
+ if (depth == 64)
+ delete[] (quint64 *)data;
+ else
+ delete[] (quint32 *)data;
+ }
data = 0;
}