diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-10-20 23:33:02 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-11-16 19:49:04 +0000 |
commit | 8d8991c697d001e3e205ad03533dc0e5ca5dde0b (patch) | |
tree | 47b8a13f5af42915d3cf88ebbed46dda1554edac /src/gui | |
parent | e655426e7ac8396713272e123fe0218380e13de1 (diff) |
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>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/image/qxbmhandler.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/gui/image/qxbmhandler.cpp b/src/gui/image/qxbmhandler.cpp index b21bc75bc4..ada2485363 100644 --- a/src/gui/image/qxbmhandler.cpp +++ b/src/gui/image/qxbmhandler.cpp @@ -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"); } } |