Make generated files more resilient to crashes

If m_resource is not initialized when calling a send_* method it will
simply crash. This change checks for it beforehand so we get a warning
instead.

Change-Id: I601f9070a35a1b3e595567991f7e54e9a6572c2d
Reviewed-by: Johan Helsing <johan.helsing@qt.io>
This commit is contained in:
Aleix Pol 2020-01-20 19:05:46 +01:00
parent b74257332f
commit ea3a3638e6

View File

@ -906,6 +906,11 @@ bool Scanner::process()
printEvent(e);
printf("\n");
printf(" {\n");
printf(" Q_ASSERT_X(m_resource, \"%s::%s\", \"Uninitialised resource\");\n", interfaceName, e.name.constData());
printf(" if (Q_UNLIKELY(!m_resource)) {\n");
printf(" qWarning(\"could not call %s::%s as it's not initialised\");\n", interfaceName, e.name.constData());
printf(" return;\n");
printf(" }\n");
printf(" send_%s(\n", e.name.constData());
printf(" m_resource->handle");
for (const WaylandArgument &a : e.arguments) {