summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-10-20 23:00:08 +0200
committerMarc Mutz <marc.mutz@kdab.com>2016-10-21 06:19:21 +0000
commit294c870bedadc7823d61bc8df6fd37323589f0a2 (patch)
tree79f2851fd525ebcce4e2fa4535aae5d58e23e1c7 /src
parentb6df7257501b54521c25587c3c5e600b2c9393d1 (diff)
QImage: cache colortable size
Coverity threw an error that in the else branch, the expression colorTableRGB16[tableSize - 1] accesses uninit'ed data. The working theory is that it fails to perform the implication isEmpty() → size() == 0 This patch, therefore, checks for size() == 0 instead of isEmpty(), which is hardly less readable and might help Coverity understand the code better. Then again, Coverity might not understand that the tableSize can never be negative. If that's the case, another patch will be needed, but let's try the simpler solution first. Coverity-Id: 11420 Change-Id: Ibfe2a798c55af95c8001fa909aa94a6c5bc7c647 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/gui/image/qimage_conversions.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/gui/image/qimage_conversions.cpp b/src/gui/image/qimage_conversions.cpp
index 7b8d88ba72..c25b4cf5c3 100644
--- a/src/gui/image/qimage_conversions.cpp
+++ b/src/gui/image/qimage_conversions.cpp
@@ -905,12 +905,12 @@ static bool convert_indexed8_to_RGB16_inplace(QImageData *data, Qt::ImageConvers
const int dest_pad = (dst_bytes_per_line >> 1) - width;
quint16 colorTableRGB16[256];
- if (data->colortable.isEmpty()) {
+ const int tableSize = data->colortable.size();
+ if (tableSize == 0) {
for (int i = 0; i < 256; ++i)
colorTableRGB16[i] = qConvertRgb32To16(qRgb(i, i, i));
} else {
// 1) convert the existing colors to RGB16
- const int tableSize = data->colortable.size();
for (int i = 0; i < tableSize; ++i)
colorTableRGB16[i] = qConvertRgb32To16(data->colortable.at(i));
data->colortable = QVector<QRgb>();