summaryrefslogtreecommitdiffstats
path: root/src/dbus
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2021-06-30 13:43:58 +0200
committerMarc Mutz <marc.mutz@kdab.com>2021-07-08 01:49:26 +0200
commitebee8a13364f28c40fbe7fae4cedaebc70d9d024 (patch)
treee9532bcab6255c7ffa2a829f1e4e7c62b2c7a0f3 /src/dbus
parent28fbed2f5cfa311067ed42268302c15b99769876 (diff)
QDBusMarshaller: fix -Wformat-overflow
Says GCC: qdbusmarshaller.cpp: In member function ‘QDBusMarshaller* QDBusMarshaller::beginMap(QMetaType, QMetaType)’: qdbusmarshaller.cpp:286:17: warning: ‘%s’ directive argument is null [-Wformat-overflow=] 286 | qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. " | ^ Fix by manual checking. It's a False Positive, because QString::asprintf() can handle nullptr strings just find, but let's make GCC happy. Since the code snippet appears multiple times, even though GCC only warns about one of them, take this opportunity to factor the code out into a cold helper function. Change-Id: I1d642f2465f34b670b179646185cba05cb16e573 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/dbus')
-rw-r--r--src/dbus/qdbusargument_p.h1
-rw-r--r--src/dbus/qdbusmarshaller.cpp41
2 files changed, 16 insertions, 26 deletions
diff --git a/src/dbus/qdbusargument_p.h b/src/dbus/qdbusargument_p.h
index 5cc3ca7da2..92ff25e81c 100644
--- a/src/dbus/qdbusargument_p.h
+++ b/src/dbus/qdbusargument_p.h
@@ -155,6 +155,7 @@ public:
bool skipSignature;
private:
+ Q_DECL_COLD_FUNCTION void unregisteredTypeError(QMetaType t);
Q_DISABLE_COPY_MOVE(QDBusMarshaller)
};
diff --git a/src/dbus/qdbusmarshaller.cpp b/src/dbus/qdbusmarshaller.cpp
index 03da1a6780..25749b66b5 100644
--- a/src/dbus/qdbusmarshaller.cpp
+++ b/src/dbus/qdbusmarshaller.cpp
@@ -59,6 +59,16 @@ QDBusMarshaller::~QDBusMarshaller()
close();
}
+void QDBusMarshaller::unregisteredTypeError(QMetaType id)
+{
+ const char *name = id.name();
+ qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
+ "Use qDBusRegisterMetaType to register it",
+ name ? name : "", id.id());
+ error(QLatin1String("Unregistered type %1 passed in arguments")
+ .arg(QLatin1String(id.name())));
+}
+
inline QString QDBusMarshaller::currentSignature()
{
if (message)
@@ -208,11 +218,7 @@ inline bool QDBusMarshaller::append(const QDBusVariant &arg)
signature = QDBusMetaType::typeToSignature(id);
}
if (!signature) {
- qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
- "Use qDBusRegisterMetaType to register it",
- id.name(), id.id());
- error(QLatin1String("Unregistered type %1 passed in arguments")
- .arg(QLatin1String(id.name())));
+ unregisteredTypeError(id);
return false;
}
@@ -250,11 +256,7 @@ inline QDBusMarshaller *QDBusMarshaller::beginArray(QMetaType id)
{
const char *signature = QDBusMetaType::typeToSignature(id);
if (!signature) {
- qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
- "Use qDBusRegisterMetaType to register it",
- id.name(), id.id());
- error(QLatin1String("Unregistered type %1 passed in arguments")
- .arg(QLatin1String(id.name())));
+ unregisteredTypeError(id);
return this;
}
@@ -265,11 +267,7 @@ inline QDBusMarshaller *QDBusMarshaller::beginMap(QMetaType kid, QMetaType vid)
{
const char *ksignature = QDBusMetaType::typeToSignature(kid);
if (!ksignature) {
- qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
- "Use qDBusRegisterMetaType to register it",
- kid.name(), kid.id());
- error(QLatin1String("Unregistered type %1 passed in arguments")
- .arg(QLatin1String(kid.name())));
+ unregisteredTypeError(kid);
return this;
}
if (ksignature[1] != 0 || !QDBusUtil::isValidBasicType(*ksignature)) {
@@ -282,12 +280,7 @@ inline QDBusMarshaller *QDBusMarshaller::beginMap(QMetaType kid, QMetaType vid)
const char *vsignature = QDBusMetaType::typeToSignature(vid);
if (!vsignature) {
- const char *typeName = vid.name();
- qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
- "Use qDBusRegisterMetaType to register it",
- typeName, vid.id());
- error(QLatin1String("Unregistered type %1 passed in arguments")
- .arg(QLatin1String(typeName)));
+ unregisteredTypeError(vid);
return this;
}
@@ -414,11 +407,7 @@ bool QDBusMarshaller::appendVariantInternal(const QVariant &arg)
const char *signature = QDBusMetaType::typeToSignature(id);
if (!signature) {
- qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
- "Use qDBusRegisterMetaType to register it",
- id.name(), id.id());
- error(QLatin1String("Unregistered type %1 passed in arguments")
- .arg(QLatin1String(id.name())));
+ unregisteredTypeError(id);
return false;
}