From: Konstantin Ritt Date: Wed, 23 May 2012 00:57:19 +0000 (+0300) Subject: Add missing QT_NO_CAST_FROM_ASCII X-Git-Tag: 071012110112~662 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f19fbcf4e3c531cdbaf82ea32da2210bea64cb1c;p=profile%2Fivi%2Fqtbase.git Add missing QT_NO_CAST_FROM_ASCII to QLatin1String's compare operators that takes const char *s or QByteArray. Such comparison leads to a potential misuse since QByteArray could contain any arbitrary data in any arbitrary encoding and QLatin1String is used to only contain strings in UTF-8 - they are just a different beasts aimed for different purposes, and since QT_NO_CAST_*_ASCII disallow indirect conversions and require the user to know what he's doing, let's be consistent here too. Change-Id: I9bf5f326495157db8a6af064d6154961b7861a7e Reviewed-by: Thiago Macieira --- diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 47ac45a..b563383 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -96,6 +96,7 @@ public: inline bool operator>=(const QString &s) const; inline bool operator<=(const QString &s) const; +#ifndef QT_NO_CAST_FROM_ASCII inline QT_ASCII_CAST_WARN bool operator==(const char *s) const; inline QT_ASCII_CAST_WARN bool operator!=(const char *s) const; inline QT_ASCII_CAST_WARN bool operator<(const char *s) const; @@ -109,6 +110,7 @@ public: inline QT_ASCII_CAST_WARN bool operator>(const QByteArray &s) const; inline QT_ASCII_CAST_WARN bool operator<=(const QByteArray &s) const; inline QT_ASCII_CAST_WARN bool operator>=(const QByteArray &s) const; +#endif // QT_NO_CAST_FROM_ASCII private: int m_size; @@ -1049,7 +1051,6 @@ inline bool operator>(QLatin1String s1, QLatin1String s2) inline bool operator>=(QLatin1String s1, QLatin1String s2) { int r = memcmp(s1.latin1(), s2.latin1(), qMin(s1.size(), s2.size())); return (r > 0) || (r == 0 && s1.size() >= s2.size()); } -#endif // QT_NO_CAST_FROM_ASCII inline QT_ASCII_CAST_WARN bool QLatin1String::operator==(const char *s) const { return QString::fromUtf8(s) == *this; } @@ -1077,7 +1078,6 @@ inline QT_ASCII_CAST_WARN bool QLatin1String::operator<=(const QByteArray &s) co inline QT_ASCII_CAST_WARN bool QLatin1String::operator>=(const QByteArray &s) const { return QString::fromUtf8(s) <= *this; } -#ifndef QT_NO_CAST_FROM_ASCII inline QT_ASCII_CAST_WARN bool QString::operator==(const QByteArray &s) const { return QString::compare_helper(constData(), size(), s.constData(), qstrnlen(s.constData(), s.size())) == 0; } inline QT_ASCII_CAST_WARN bool QString::operator!=(const QByteArray &s) const