QXbmHandler: don't construct a QByteArray just to find '0x' in text
Even QByteArray::fromRawData() allocates memory. Instead of QByteArray::contains() and indexOf(), use good ol' strstr(), like already done elsewhere in the same function. Apart from the memory allocations saved, this fixes a Coverity error complaining that indexOf() can return -1. It's a false positive on the first occurrence, because we didn't call that function unless we know there is a "0x" in the string, but the second _was_ wrong, because we applied it on a new buffer, with unknown content. Coverity-Id: 11262 Change-Id: I18f352c5576e24f89a5c3ef7f2f1b2176f2a235d Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
e655426e7a
commit
8d8991c697
@ -118,17 +118,18 @@ static bool read_xbm_body(QIODevice *device, int w, int h, QImage *outImage)
|
||||
|
||||
qint64 readBytes = 0;
|
||||
|
||||
char *p;
|
||||
|
||||
// scan for database
|
||||
for (;;) {
|
||||
do {
|
||||
if ((readBytes = device->readLine(buf, buflen)) <= 0) {
|
||||
// end of file
|
||||
return false;
|
||||
}
|
||||
|
||||
buf[readBytes] = '\0';
|
||||
if (QByteArray::fromRawData(buf, readBytes).contains("0x"))
|
||||
break;
|
||||
}
|
||||
p = strstr(buf, "0x");
|
||||
} while (!p);
|
||||
|
||||
if (outImage->size() != QSize(w, h) || outImage->format() != QImage::Format_MonoLSB) {
|
||||
*outImage = QImage(w, h, QImage::Format_MonoLSB);
|
||||
@ -142,7 +143,6 @@ static bool read_xbm_body(QIODevice *device, int w, int h, QImage *outImage)
|
||||
|
||||
int x = 0, y = 0;
|
||||
uchar *b = outImage->scanLine(0);
|
||||
char *p = buf + QByteArray::fromRawData(buf, readBytes).indexOf("0x");
|
||||
w = (w+7)/8; // byte width
|
||||
|
||||
while (y < h) { // for all encoded bytes...
|
||||
@ -158,7 +158,7 @@ static bool read_xbm_body(QIODevice *device, int w, int h, QImage *outImage)
|
||||
if ((readBytes = device->readLine(buf,buflen)) <= 0) // EOF ==> truncated image
|
||||
break;
|
||||
buf[readBytes] = '\0';
|
||||
p = buf + QByteArray::fromRawData(buf, readBytes).indexOf("0x");
|
||||
p = strstr(buf, "0x");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user