QXBMHandler: use QtMiscUtils, not <ctype.h>
The latter are locale-dependent, and while that doesn't produce wrong results here¹, it means they need to be out-of-line, whereas QtMiscUtils functions are inline constexpr. ¹ isdigit could give a false positive on non-US-ASCII-digits, I suppose. As a drive-by, rely on the QtMiscUtils::fromHex() returning a negative value when a non-hex character was encountered, to avoid the extra isxdigit() checks. This property is preserved through the bit manipulations: ORing together negative values yields a negative number iff either or both operands were negative (in two's complement, which Qt requires). The caller also checks the array bounds before calling, so the isxdigit() calls didn't act as an implicit bounds check (returning false if they encounter '\0'), either. Task-number: QTBUG-109235 Change-Id: I4cd734468e223f1047a53afd264d077b28cb5f1d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 115b1eab86d0395dc29f90d271bfdd29d425442e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
9a20ca1fe2
commit
6098859538
@ -10,9 +10,9 @@
|
||||
#include <qiodevice.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qvariant.h>
|
||||
#include <private/qtools_p.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -24,8 +24,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcImageIo)
|
||||
|
||||
static inline int hex2byte(char *p)
|
||||
{
|
||||
return ((isdigit((uchar) *p) ? *p - '0' : toupper((uchar) *p) - 'A' + 10) << 4) |
|
||||
(isdigit((uchar) *(p+1)) ? *(p+1) - '0' : toupper((uchar) *(p+1)) - 'A' + 10);
|
||||
return QtMiscUtils::fromHex(p[0]) * 16 | QtMiscUtils::fromHex(p[1]);
|
||||
}
|
||||
|
||||
static bool read_xbm_header(QIODevice *device, int& w, int& h)
|
||||
@ -129,9 +128,10 @@ static bool read_xbm_body(QIODevice *device, int w, int h, QImage *outImage)
|
||||
|
||||
while (y < h) { // for all encoded bytes...
|
||||
if (p && p < (buf + readBytes - 3)) { // p = "0x.."
|
||||
if (!isxdigit(p[2]) || !isxdigit(p[3]))
|
||||
const int byte = hex2byte(p + 2);
|
||||
if (byte < 0) // non-hex char encountered
|
||||
return false;
|
||||
*b++ = hex2byte(p+2);
|
||||
*b++ = byte;
|
||||
p += 2;
|
||||
if (++x == w && ++y < h) {
|
||||
b = outImage->scanLine(y);
|
||||
|
Loading…
x
Reference in New Issue
Block a user