summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Solovev <[email protected]>2025-04-07 17:31:15 +0200
committerIvan Solovev <[email protected]>2025-04-10 13:49:46 +0200
commit92c2ebdbcca9cfae6e4048004b3bdb58af972209 (patch)
treebaf11208dfe2a60e6e862e4d9080d4747adc92ae
parent1e63707f961748a0bbdd8cbda897cf72f4b96905 (diff)
qdbusxml2cpp: initialize the return value for adapters
If the interface has a method with a specified return value, the generated adapter will contain a code like: bool out; QMetaObject::invokeMethod(parent(), "Func", Q_RETURN_ARG(bool, out)); return out; In this case Q_RETURN_ARG macro makes sure that the variable `out` is properly initialized before being returned from a function, but only if invokeMethod() call is executed successfully. Update the generator to zero-initialize (or value-initialize) the return variable, so that it returns some reasonable value even if invokeMethod() fails. Extend the unit-tests to make sure that the generated adapters always initialize the return variables. Coverity-Id: 479703 Pick-to: 6.9 6.8 6.5 Change-Id: I4d15ccc6844b5ca454ab9f0cf72fd8e3f0c1b704 Reviewed-by: Matthias Rauter <[email protected]>
-rw-r--r--src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp5
-rw-r--r--tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp8
2 files changed, 9 insertions, 4 deletions
diff --git a/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp b/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp
index 0b089178835..f727e7094d6 100644
--- a/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp
+++ b/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp
@@ -1089,9 +1089,10 @@ void QDBusXmlToCpp::writeAdaptor(const QString &filename,
if (usingInvokeMethod) {
// we are using QMetaObject::invokeMethod
- if (!returnType.isEmpty())
+ if (!returnType.isEmpty()) {
cs << " " << returnType << " " << argNames.at(method.inputArgs.size())
- << ";\n";
+ << "{};\n";
+ }
static const char invoke[] = " QMetaObject::invokeMethod(parent(), \"";
cs << invoke << name << "\"";
diff --git a/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp b/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp
index 5474c4f7470..146f591bad0 100644
--- a/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp
+++ b/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp
@@ -203,7 +203,9 @@ void tst_qdbusxml2cpp::process_data()
.arg(basicTypeList[i].dbusType)
<< QRegularExpression(QString("Q_SLOTS:.*\\bQDBusPendingReply<%1> Method\\((const )?%1 ")
.arg(basicTypeList[i].cppType), QRegularExpression::DotMatchesEverythingOption)
- << QRegularExpression(QString("Q_SLOTS:.*\\b%1 Method\\((const )?%1 ")
+ << QRegularExpression(QString("Q_SLOTS:.*\\b%1 Method\\((const )?%1 &?in0\\);"
+ ".*%1 .*::Method\\((const )?%1 &?in0\\)\n{\n"
+ ".*%1 out0{};")
.arg(basicTypeList[i].cppType), QRegularExpression::DotMatchesEverythingOption);
}
@@ -226,7 +228,9 @@ void tst_qdbusxml2cpp::process_data()
"</method>"
<< QRegularExpression("Q_SLOTS:.*\\bQDBusPendingReply<Point> Method\\(PointF ",
QRegularExpression::DotMatchesEverythingOption)
- << QRegularExpression("Q_SLOTS:.*\\bPoint Method\\(PointF ",
+ << QRegularExpression("Q_SLOTS:.*\\bPoint Method\\(PointF in0\\);"
+ ".*Point .*::Method\\(PointF in0\\)\n{\n"
+ ".*Point out0{};",
QRegularExpression::DotMatchesEverythingOption);
QTest::newRow("method-ss")