From 5c24c14a0e0fb3bb536e29d0d9abc5980640a4d1 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 25 Jul 2014 13:47:49 +0200 Subject: Windows: Streamline rawfont-lookup code. Fix ugly warnings by MinGW: qwindowsfontdatabase.cpp: In member function '{anonymous}::TableDirectory* {anonymous}::EmbeddedFont::tableDirectoryEntry(const QByteArray&)':qwindowsfontdatabase.cpp:167:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if (Q_UNLIKELY(m_fontData.size() < sizeof(OffsetSubTable))) ^ ..\..\..\..\include/QtCore/../../src/corelib/global/qcompilerdetection.h:202:49: note: in definition of macro 'Q_UNLIKELY' Change-Id: I47fac598ed1b6623146fb437c00da64d8e8b6984 Reviewed-by: Kai Koehne Reviewed-by: Konstantin Ritt --- .../platforms/windows/qwindowsfontdatabase.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp index aad6c8cf31..363d8b2d5c 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp @@ -164,25 +164,24 @@ namespace { { Q_ASSERT(tagName.size() == 4); quint32 tagId = *(reinterpret_cast(tagName.constData())); - if (Q_UNLIKELY(m_fontData.size() < sizeof(OffsetSubTable))) + const size_t fontDataSize = m_fontData.size(); + if (Q_UNLIKELY(fontDataSize < sizeof(OffsetSubTable))) return 0; OffsetSubTable *offsetSubTable = reinterpret_cast(m_fontData.data()); TableDirectory *tableDirectory = reinterpret_cast(offsetSubTable + 1); - quint16 tableCount = qFromBigEndian(offsetSubTable->numTables); - if (Q_UNLIKELY(quint32(m_fontData.size()) < sizeof(OffsetSubTable) + sizeof(TableDirectory) * tableCount)) + const size_t tableCount = qFromBigEndian(offsetSubTable->numTables); + if (Q_UNLIKELY(fontDataSize < sizeof(OffsetSubTable) + sizeof(TableDirectory) * tableCount)) return 0; - TableDirectory *nameTableDirectoryEntry = 0; - for (int i = 0; i < tableCount; ++i, ++tableDirectory) { - if (tableDirectory->identifier == tagId) { - nameTableDirectoryEntry = tableDirectory; - break; - } + TableDirectory *tableDirectoryEnd = tableDirectory + tableCount; + for (TableDirectory *entry = tableDirectory; entry < tableDirectoryEnd; ++entry) { + if (entry->identifier == tagId) + return entry; } - return nameTableDirectoryEntry; + return 0; } QString EmbeddedFont::familyName(TableDirectory *nameTableDirectoryEntry) -- cgit v1.2.3