avoid temporary in QImageData::create()

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-07-29 20:26:16 +03:00
parent 0e44c3b18a
commit d418199d5c

View file

@ -610,19 +610,20 @@ QImageData *QImageData::create(uchar *data, int width, int height, int bpl, QIm
return Q_NULLPTR;
const int depth = qt_depthForFormat(format);
const int calc_bytes_per_line = ((width * depth + 31)/32) * 4;
const int min_bytes_per_line = (width * depth + 7)/8;
if (bpl <= 0)
bpl = calc_bytes_per_line;
if (bpl <= 0) {
bpl = ((width * depth + 31)/32) * 4;
}
if (width <= 0 || height <= 0 || !data
if (Q_UNLIKELY(width <= 0 || height <= 0 || !data
|| INT_MAX/sizeof(uchar *) < uint(height)
|| INT_MAX/uint(depth) < uint(width)
|| bpl <= 0
|| bpl < min_bytes_per_line
|| INT_MAX/uint(bpl) < uint(height))
return Q_NULLPTR; // invalid parameter(s)
|| INT_MAX/uint(bpl) < uint(height))) {
return Q_NULLPTR; // invalid parameter(s)
}
QScopedPointer<QImageData> d(new QImageData);