diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2022-10-17 10:35:45 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2022-10-31 15:10:52 +0200 |
commit | ab7f354df2d4381a4bf9aaa7e1f8d89c076d3806 (patch) | |
tree | 816a815c7c571116034752c1f0bd6dd4707398ca /src/qml/qml/ftw/qhashedstring_p.h | |
parent | 705659eaaf47af72eeb5f5c742e18a5c665a76eb (diff) |
QHashedStringRef: assert that strings have at most INT_MAX size
That's a sane limitation for any use case of this class. Moreover,
explicitly cast length to int in the constructors.
As a drive-by, pass QLatin1String by value, and use the nowadays
preferred QLatin1StringView name.
Task-number: QTBUG-105055
Change-Id: I2fa406ec6167eb80782bb39e0cfacc3c5712517c
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/qml/ftw/qhashedstring_p.h')
-rw-r--r-- | src/qml/qml/ftw/qhashedstring_p.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/qml/qml/ftw/qhashedstring_p.h b/src/qml/qml/ftw/qhashedstring_p.h index 5e002fcbee..4de5524a10 100644 --- a/src/qml/qml/ftw/qhashedstring_p.h +++ b/src/qml/qml/ftw/qhashedstring_p.h @@ -199,14 +199,18 @@ QHashedStringRef::QHashedStringRef() { } +// QHashedStringRef is meant for identifiers, property names, etc. +// Those should alsways be smaller than std::numeric_limits<int>::max()) QHashedStringRef::QHashedStringRef(const QString &str) -: m_data(str.constData()), m_length(str.size()), m_hash(0) +: m_data(str.constData()), m_length(int(str.size())), m_hash(0) { + Q_ASSERT(str.size() <= std::numeric_limits<int>::max()); } QHashedStringRef::QHashedStringRef(QStringView str) -: m_data(str.constData()), m_length(str.size()), m_hash(0) +: m_data(str.constData()), m_length(int(str.size())), m_hash(0) { + Q_ASSERT(str.size() <= std::numeric_limits<int>::max()); } QHashedStringRef::QHashedStringRef(const QChar *data, int length) @@ -220,8 +224,9 @@ QHashedStringRef::QHashedStringRef(const QChar *data, int length, quint32 hash) } QHashedStringRef::QHashedStringRef(const QHashedString &string) -: m_data(string.constData()), m_length(string.size()), m_hash(string.m_hash) +: m_data(string.constData()), m_length(int(string.size())), m_hash(string.m_hash) { + Q_ASSERT(string.size() <= std::numeric_limits<int>::max()); } QHashedStringRef::QHashedStringRef(const QHashedStringRef &string) @@ -424,7 +429,7 @@ quint32 QHashedString::stringHash(const char *data, int length) void QHashedString::computeHash() const { - m_hash = stringHash(constData(), size()); + m_hash = stringHash(constData(), int(size())); } namespace QtPrivate { |