aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/common
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-04-16 11:40:10 +0200
committerUlf Hermann <ulf.hermann@qt.io>2024-04-26 07:13:50 +0200
commit23fc22e16022e355f2a1aff8705c09b807fbe024 (patch)
tree1e30c3c7d5897fa1e48071a8d0238083baff82a9 /src/qml/common
parent372db480cda5899148629d8edad76405bc1b98de (diff)
QmlCompiler: Consider lengths to be qsizetype
This is what we get as "source material" from all the containers. In JavaScript, arrays sizes are up to 32bit unsigned, but we need to represent -1 in a few places. Therefore, we cannot clamp the result to 32bit signed if the underlying container supports 64bit indices. We can change qjslist.h here because this header is only supposed to be used from generated code. Therefore, if you rebuild any users of this code, you will also re-generate them, adapting to the new API. Since we check for QJSNumberCoercion::isArrayIndex() before we use any number as an array index when generating code, this is actually safe. We just need to adapt isArrayIndex() to consider numbers greater than INT_MAX as possible values. Fixes: QTBUG-122582 Change-Id: I1147978a05bfedb63037c7f4437921f85a6aabb1 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/common')
-rw-r--r--src/qml/common/qjsnumbercoercion.cpp18
-rw-r--r--src/qml/common/qjsnumbercoercion.h17
2 files changed, 30 insertions, 5 deletions
diff --git a/src/qml/common/qjsnumbercoercion.cpp b/src/qml/common/qjsnumbercoercion.cpp
index ba76c12bb0..8cd96a4e25 100644
--- a/src/qml/common/qjsnumbercoercion.cpp
+++ b/src/qml/common/qjsnumbercoercion.cpp
@@ -24,10 +24,26 @@ QT_BEGIN_NAMESPACE
\internal
Checks whether \a d contains a value that can serve as an index into an array.
- For that, \a d must be a non-negative value representable as an int.
+ For that, \a d must be a non-negative value representable as an unsigned 32bit int.
*/
/*!
+ \fn bool QJSNumberCoercion::isArrayIndex(qint64 i)
+ \internal
+
+ Checks whether \a i contains a value that can serve as an index into an array.
+ For that, \a d must be a non-negative value representable as an unsigned 32bit int.
+*/
+
+/*!
+ \fn bool QJSNumberCoercion::isArrayIndex(quint64 i)
+ \internal
+
+ Checks whether \a i contains a value that can serve as an index into an array.
+ For that, \a d must be a value representable as an unsigned 32bit int.
+*/
+
+/*!
\fn int QJSNumberCoercion::toInteger(double d)
\internal
diff --git a/src/qml/common/qjsnumbercoercion.h b/src/qml/common/qjsnumbercoercion.h
index 569976454f..0023bff6e8 100644
--- a/src/qml/common/qjsnumbercoercion.h
+++ b/src/qml/common/qjsnumbercoercion.h
@@ -27,11 +27,20 @@ public:
static constexpr bool isArrayIndex(double d)
{
- if (d < 0 || !equals(d, d) || d > (std::numeric_limits<int>::max)()) {
- return false;
- }
+ return d >= 0
+ && equals(d, d)
+ && d <= (std::numeric_limits<uint>::max)()
+ && equals(static_cast<uint>(d), d);
+ }
- return equals(static_cast<int>(d), d);
+ static constexpr bool isArrayIndex(qint64 i)
+ {
+ return i >= 0 && i <= (std::numeric_limits<uint>::max)();
+ }
+
+ static constexpr bool isArrayIndex(quint64 i)
+ {
+ return i <= (std::numeric_limits<uint>::max)();
}
static constexpr int toInteger(double d) {