Fixed crash due to missing null pointer check.

This commit is contained in:
orbitcowboy 2022-06-02 11:32:55 +02:00
parent 50c612b7d9
commit 58460edaf8
2 changed files with 12 additions and 1 deletions

View File

@ -139,7 +139,7 @@ void CheckFunctions::invalidFunctionUsage()
const Variable* const variable = argtok->variable(); const Variable* const variable = argtok->variable();
// Is non-null terminated local variable of type char (e.g. char buf[] = {'x'};) ? // Is non-null terminated local variable of type char (e.g. char buf[] = {'x'};) ?
if (variable && variable->isLocal() if (variable && variable->isLocal()
&& valueType->type == ValueType::Type::CHAR) { && valueType && valueType->type == ValueType::Type::CHAR) {
const Token* varTok = variable->declEndToken(); const Token* varTok = variable->declEndToken();
auto count = -1; // Find out explicitly set count, e.g.: char buf[3] = {...}. Variable 'count' is set to 3 then. auto count = -1; // Find out explicitly set count, e.g.: char buf[3] = {...}. Variable 'count' is set to 3 then.
if (varTok && Token::simpleMatch(varTok->previous(), "]")) if (varTok && Token::simpleMatch(varTok->previous(), "]"))

View File

@ -649,6 +649,17 @@ private:
" return fopen(fileName, \"r\"); \n" " return fopen(fileName, \"r\"); \n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("void scanMetaTypes()\n" // don't crash
"{\n"
" QVector<int> metaTypes;\n"
" for (int mtId = 0; mtId <= QMetaType::User; ++mtId) {\n"
" const auto name = QMetaType::typeName(mtId);\n"
" if (strstr(name, \"GammaRay::\") != name)\n"
" metaTypes.push_back(mtId);\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
void mathfunctionCall_sqrt() { void mathfunctionCall_sqrt() {