summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qstring.h
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@digia.com>2012-09-26 12:32:52 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-09-29 02:31:35 +0200
commit8e90e0805f2981014d3382d8841617b4c56dfc50 (patch)
tree5aa341addb3fca877b34436f23f483937ab972c7 /src/corelib/tools/qstring.h
parent4c33efc3228d82a82e13fe8c196b8c74a4998572 (diff)
Prevent an overflow warning in assertions.
Functions like QByteArray::at() assert the given index: Q_ASSERT(i >= 0 && i < size(); These functions typically get inlined. Now if the index is e.g. size() - 2, then gcc will emit an ugly warning in client code ("assuming signed overflow does not occur when assuming that (X - c) > X is always false"). This can be easily prevented by casting both sides of the second comparison in the assertion to their unsigned type. The explicit comparison to zero is then no longer necessary, since that condition is tested implicitly by the other comparison due to unsigned arithmetic. Change-Id: Ic7244e1fa5da00a47d1fe0ed56fb81c23d444dfe Reviewed-by: hjk <qthjk@ovi.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qstring.h')
-rw-r--r--src/corelib/tools/qstring.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index 5b48a53179..47cca0d280 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -1245,7 +1245,7 @@ public:
QStringRef appendTo(QString *string) const;
inline const QChar at(int i) const
- { Q_ASSERT(i >= 0 && i < size()); return m_string->at(i + m_position); }
+ { Q_ASSERT(uint(i) < uint(size())); return m_string->at(i + m_position); }
#ifndef QT_NO_CAST_FROM_ASCII
// ASCII compatibility