diff options
author | Erik Verbruggen <erik.verbruggen@theqtcompany.com> | 2016-04-21 14:41:02 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2016-05-16 12:32:56 +0000 |
commit | 27567f7c4cb9c74c2ad3829f716caf8c5095b16b (patch) | |
tree | 0db5de02953af66826aa5370eb98e83c0dc7816b /src/qml/jsruntime/qv4string.cpp | |
parent | 1c51ae2911636e61a698967fd9c6aabd28f5ceb9 (diff) |
V4: Use built-in overflow checking add/mul for index calculation.
This signals the compiler the actual intent (i.e. it doesn't rely on
unsigned int overflow behavior) and even allows for slightly better
code generation.
Change-Id: I915ebbeab2e60decb6adf816e9cf010ab41d172a
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
Reviewed-by: Frank Meerkoetter <frank.meerkoetter@basyskom.com>
Diffstat (limited to 'src/qml/jsruntime/qv4string.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4string.cpp | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/src/qml/jsruntime/qv4string.cpp b/src/qml/jsruntime/qv4string.cpp index 1455a06c4a..7c965ce441 100644 --- a/src/qml/jsruntime/qv4string.cpp +++ b/src/qml/jsruntime/qv4string.cpp @@ -46,6 +46,7 @@ #include "qv4stringobject_p.h" #endif #include <QtCore/QHash> +#include <QtCore/private/qnumeric_p.h> using namespace QV4; @@ -69,11 +70,8 @@ static inline uint toArrayIndex(const T *ch, const T *end) uint x = toUInt(ch) - '0'; if (x > 9) return UINT_MAX; - uint n = i*10 + x; - if (n < i) - // overflow + if (mul_overflow(i, uint(10), &i) || add_overflow(i, x, &i)) return UINT_MAX; - i = n; ++ch; } return i; |