diff options
| author | Ahmad Samir <a.samirh78@gmail.com> | 2025-09-04 16:33:16 +0300 |
|---|---|---|
| committer | Ahmad Samir <a.samirh78@gmail.com> | 2025-09-08 03:36:44 +0300 |
| commit | db2bbbb251c041b37d529e5722c4f4a244988857 (patch) | |
| tree | b4268bd8cde5975b2b7679ab6001bf375376bcaf /src/corelib/kernel/qmetaobjectbuilder.cpp | |
| parent | 285adfd59cc290d0bfd36d32a9802c8b9b9086c8 (diff) | |
QMetaObjectBuilder: add assert to setParameterNames()
Amends 58b4be482cb481addebc966d713bc0521cca3218; we have:
QList<QByteArray> paramNames = method.parameterNames;
The above commit changed the code from:
while (paramNames.size() < paramCount)
paramNames.append(QByteArray());
for (int i = 0; i < paramCount; ++i)
To:
if (paramNames.size() < paramCount) // (paraphrased for brevity)
paramNames.resize(paramCount);
for (auto &foo : paramNames)
Calling something like this:
methodBuilder = builder.addSlot("foo(int)");
methodBuilder.setParameterNames({"", "i"});
Worked with the code before that commit, where it just used the first
element in `paramNames` and didn't look at the second one at all.
The new for-loop, `for (auto &foo : paramNames)`, iterated
paraNames.size() times, which led to the `dataIndex` being off by one.
Which would eventually hit an assert in buildMetaObject():
Q_ASSERT(!buf || dataIndex == pmeta->propertyData);
Friedemann Kleint debugged the issue in the bug report, so this patch
applies his suggestion of adding an assert in setParameterNames(), right
where the bug actually happens, because the assert in buildMetaObject()
makes it hard to connect the dots and fix the actual bug in user code.
Fixes: QTBUG-139845
Pick-to: 6.10
Done-with: Friedemann Kleint <Friedemann.Kleint@qt.io>
Change-Id: Icd355241834396c1c8659df621d0f785ef0cceee
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qmetaobjectbuilder.cpp')
| -rw-r--r-- | src/corelib/kernel/qmetaobjectbuilder.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/corelib/kernel/qmetaobjectbuilder.cpp b/src/corelib/kernel/qmetaobjectbuilder.cpp index 5dd86d4b0e4..a2719f97da7 100644 --- a/src/corelib/kernel/qmetaobjectbuilder.cpp +++ b/src/corelib/kernel/qmetaobjectbuilder.cpp @@ -1649,6 +1649,7 @@ QList<QByteArray> QMetaMethodBuilder::parameterNames() const void QMetaMethodBuilder::setParameterNames(const QList<QByteArray> &value) { QMetaMethodBuilderPrivate *d = d_func(); + Q_ASSERT(d->parameterCount() >= value.size()); if (d) d->parameterNames = value; } |
