diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-05-02 10:20:14 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-05-02 14:20:59 +0000 |
commit | 61d04ded2b3f5ca968ed6379a72b0abf2fb49b46 (patch) | |
tree | ba2f2b9c0fbae199ced680c7811a2e9f426133fe /src/qml/jsruntime/qv4value_p.h | |
parent | 0ee2d9be1f8ab706a193e4f0cf095ee79e8210a8 (diff) |
Fix asan warnings
Don't try to allocate an array buffer with negative length.
Change-Id: Ie95b9bcf7a3108b47df27ef813b7922e9da42b17
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4value_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4value_p.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h index 97c6ea23ff..c3a927fa91 100644 --- a/src/qml/jsruntime/qv4value_p.h +++ b/src/qml/jsruntime/qv4value_p.h @@ -402,6 +402,7 @@ public: inline int toInt32() const; inline unsigned int toUInt32() const; qint64 toLength() const; + inline qint64 toIndex() const; bool toBoolean() const { if (integerCompatible()) @@ -833,6 +834,19 @@ inline qint64 Value::toLength() const return static_cast<qint64>(i); } +inline qint64 Value::toIndex() const +{ + qint64 idx; + if (Q_LIKELY(integerCompatible())) { + idx = int_32(); + } else { + idx = static_cast<qint64>(Primitive::toInteger(isDouble() ? doubleValue() : toNumberImpl())); + } + if (idx > (static_cast<qint64>(1) << 53) - 1) + idx = -1; + return idx; +} + inline double Value::toInteger() const { if (integerCompatible()) |