summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-11-16 17:24:09 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-11-28 09:11:28 +0000
commitae8389e19c5804c867b2981311c623003a691474 (patch)
tree7666e90c1539b424c695ba01553b9200b4be79ca /src/gui
parentd8962144b425b9929770b67bcfb8247a9e9b9022 (diff)
Ensure alignment of image-data
Instead of relying on the return value of malloc having the correct alignment, use proper non-throwing new[] operators. Change-Id: I06c6c619e21c848f3d184bdb7cef8c5589c1c7ab Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/gui')
-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;
}