aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2022-10-17 09:37:32 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2022-10-31 15:10:52 +0200
commite34a232d5c175b9504c6713eb9dc7ed373456801 (patch)
tree0acf5f141c292892bc12fb132e1ed61b7f030f06
parent4c930c2ce51b3a3fe3c51d748c85bdafde940227 (diff)
Avoid -Wshorten-64-to-32 warnings in a few places
...by explictily casting to int. Add a few comments explaining why we can get at most INT_MAX many elements, and add Q_ASSERTS to check that the assumptions actually hold. Task-number: QTBUG-105055 Change-Id: I1769318a9c04b51efe45fe0cae9fc0d93cfec45e Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/qml/common/qv4compileddata_p.h4
-rw-r--r--src/qml/common/qv4staticvalue_p.h2
-rw-r--r--src/qml/jsruntime/qv4string_p.h3
-rw-r--r--src/qml/memory/qv4mmdefs_p.h10
-rw-r--r--src/qml/qml/qqmlcontext_p.h6
-rw-r--r--src/qml/qml/qqmlpropertycachevector_p.h7
6 files changed, 22 insertions, 10 deletions
diff --git a/src/qml/common/qv4compileddata_p.h b/src/qml/common/qv4compileddata_p.h
index f2adced909..93183865e7 100644
--- a/src/qml/common/qv4compileddata_p.h
+++ b/src/qml/common/qv4compileddata_p.h
@@ -231,7 +231,9 @@ struct String
qint32_le size;
static int calculateSize(const QString &str) {
- return (sizeof(String) + (str.size() + 1) * sizeof(quint16) + 7) & ~0x7;
+ // we cannot enconuter strings larger than INT_MAX anyway, as such a string
+ // would already break in other parts of the compilation process
+ return (sizeof(String) + (int(str.size()) + 1) * sizeof(quint16) + 7) & ~0x7;
}
};
diff --git a/src/qml/common/qv4staticvalue_p.h b/src/qml/common/qv4staticvalue_p.h
index 001666d08a..896a31bdf2 100644
--- a/src/qml/common/qv4staticvalue_p.h
+++ b/src/qml/common/qv4staticvalue_p.h
@@ -167,7 +167,7 @@ struct StaticValue
};
inline Type type() const {
- int t = quickType();
+ auto t = quickType();
if (t < QT_Empty)
return _val ? Managed_Type : Undefined_Type;
if (t > QT_Int)
diff --git a/src/qml/jsruntime/qv4string_p.h b/src/qml/jsruntime/qv4string_p.h
index a546da1ea7..78727bdcc3 100644
--- a/src/qml/jsruntime/qv4string_p.h
+++ b/src/qml/jsruntime/qv4string_p.h
@@ -130,7 +130,8 @@ Q_STATIC_ASSERT(std::is_trivial_v<ComplexString>);
inline
int String::length() const {
- return subtype < StringType_AddedString ? text().size : static_cast<const ComplexString *>(this)->len;
+ // TODO: ensure that our strings never actually grow larger than INT_MAX
+ return subtype < StringType_AddedString ? int(text().size) : static_cast<const ComplexString *>(this)->len;
}
}
diff --git a/src/qml/memory/qv4mmdefs_p.h b/src/qml/memory/qv4mmdefs_p.h
index 395f0870e4..c873bfd5f8 100644
--- a/src/qml/memory/qv4mmdefs_p.h
+++ b/src/qml/memory/qv4mmdefs_p.h
@@ -178,17 +178,17 @@ struct HeapItem {
bool isGray() const {
Chunk *c = chunk();
- uint index = this - c->realBase();
+ std::ptrdiff_t index = this - c->realBase();
return Chunk::testBit(c->grayBitmap, index);
}
bool isBlack() const {
Chunk *c = chunk();
- uint index = this - c->realBase();
+ std::ptrdiff_t index = this - c->realBase();
return Chunk::testBit(c->blackBitmap, index);
}
bool isInUse() const {
Chunk *c = chunk();
- uint index = this - c->realBase();
+ std::ptrdiff_t index = this - c->realBase();
return Chunk::testBit(c->objectBitmap, index);
}
@@ -207,10 +207,10 @@ struct HeapItem {
// Doesn't report correctly for huge items
size_t size() const {
Chunk *c = chunk();
- uint index = this - c->realBase();
+ std::ptrdiff_t index = this - c->realBase();
Q_ASSERT(Chunk::testBit(c->objectBitmap, index));
// ### optimize me
- uint end = index + 1;
+ std::ptrdiff_t end = index + 1;
while (end < Chunk::NumSlots && Chunk::testBit(c->extendsBitmap, end))
++end;
return (end - index)*sizeof(HeapItem);
diff --git a/src/qml/qml/qqmlcontext_p.h b/src/qml/qml/qqmlcontext_p.h
index 5489afb892..aeaa1a3cd5 100644
--- a/src/qml/qml/qqmlcontext_p.h
+++ b/src/qml/qml/qqmlcontext_p.h
@@ -50,7 +50,11 @@ public:
int notifyIndex() const { return m_notifyIndex; }
void setNotifyIndex(int notifyIndex) { m_notifyIndex = notifyIndex; }
- int numPropertyValues() const { return m_propertyValues.size(); }
+ int numPropertyValues() const {
+ auto size = m_propertyValues.size();
+ Q_ASSERT(size <= std::numeric_limits<int>::max());
+ return int(size);
+ }
void appendPropertyValue(const QVariant &value) { m_propertyValues.append(value); }
void setPropertyValue(int index, const QVariant &value) { m_propertyValues[index] = value; }
QVariant propertyValue(int index) const { return m_propertyValues[index]; }
diff --git a/src/qml/qml/qqmlpropertycachevector_p.h b/src/qml/qml/qqmlpropertycachevector_p.h
index 6386795086..a208b3fa6e 100644
--- a/src/qml/qml/qqmlpropertycachevector_p.h
+++ b/src/qml/qml/qqmlpropertycachevector_p.h
@@ -36,7 +36,10 @@ public:
return data.resize(size);
}
- int count() const { return data.size(); }
+ int count() const {
+ // the property cache vector will never contain more thant INT_MAX many elements
+ return int(data.size());
+ }
void clear()
{
for (int i = 0; i < data.size(); ++i) {
@@ -55,12 +58,14 @@ public:
cache->addref();
data.append(QBiPointer<const QQmlPropertyCache, QQmlPropertyCache>(cache.data()));
Q_ASSERT(data.last().isT1());
+ Q_ASSERT(data.size() <= std::numeric_limits<int>::max());
}
void appendOwn(const QQmlPropertyCache::Ptr &cache) {
cache->addref();
data.append(QBiPointer<const QQmlPropertyCache, QQmlPropertyCache>(cache.data()));
Q_ASSERT(data.last().isT2());
+ Q_ASSERT(data.size() <= std::numeric_limits<int>::max());
}
QQmlPropertyCache::ConstPtr at(int index) const