CheckLeakAutoVar: fix crash on unknown macro (#5836)

This commit is contained in:
chrchr-github 2024-01-05 13:24:01 +01:00 committed by GitHub
parent 02f474bc19
commit f9134a69d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -1046,10 +1046,10 @@ void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpenin
changeAllocStatus(varInfo, sp_allocation, vtok, vtok);
} else {
const Token* const nextArg = funcArg->nextArgument();
do {
while (arg && ((nextArg && arg != nextArg) || (!nextArg && arg != tokOpeningPar->link()))) {
checkTokenInsideExpression(arg, varInfo, /*inFuncCall*/ isLeakIgnore);
arg = arg->next();
} while ((nextArg && arg != nextArg) || (!nextArg && arg != tokOpeningPar->link()));
}
}
// TODO: check each token in argument expression (could contain multiple variables)
argNr++;

View File

@ -981,6 +981,11 @@ private:
ASSERT_EQUALS("[test.c:4]: (error) Dereferencing 'p' after it is deallocated / released\n"
"[test.c:7] -> [test.c:8]: (error) Returning/dereferencing 'p' after it is deallocated / released\n",
errout.str());
check("void f() {\n"
" FOREACH(callables, ());\n"
"}\n");
ASSERT_EQUALS("[test.c:2]: (information) --check-library: Function FOREACH() should have <noreturn> configuration\n", errout.str()); // don't crash
}
void doublefree1() { // #3895