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>
This commit is contained in:
Marc Mutz 2016-10-20 23:00:08 +02:00
parent b6df725750
commit 294c870bed

View File

@ -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>();