CppQuickFixes: Fix possible null dereference

It may happen that we dereference null inside the following
condition:

  if (declarator->postfix_declarator_list)

This may happen in case we entered the "if (!declarator)"
condition, but didn't fulfill the nested
"if (path.at(n - i++)->asPointer())" condition.

Detected by clazy analyzer.

Change-Id: I47135bc5648459e91664a4f65f9752b58248a496
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2022-12-07 17:15:10 +01:00
parent b0e6943491
commit 154e3df17e

View File

@@ -4310,6 +4310,8 @@ void GenerateGetterSetter::match(const CppQuickFixInterface &interface, QuickFix
return;
declarator = path.at(n - i++)->asDeclarator();
}
if (!declarator)
return;
}
const auto variableDecl = path.at(n - i++)->asSimpleDeclaration();
const auto classSpecifier = path.at(n - i++)->asClassSpecifier();