Uninitialized variables; Fixed FP when returning malloc pointer

This commit is contained in:
Daniel Marjamäki 2021-05-21 17:10:49 +02:00
parent 2d3d7db730
commit 68c46e146d
2 changed files with 9 additions and 1 deletions

View File

@ -1165,6 +1165,8 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer,
return nullptr;
if (alloc == CTOR_CALL && derefValue && Token::simpleMatch(derefValue->astParent(), "(") && astIsLhs(derefValue))
return nullptr;
if (Token::simpleMatch(valueExpr->astParent(), "return"))
return nullptr;
}
// Passing variable to function..

View File

@ -4127,7 +4127,7 @@ private:
"void f() {\n"
" struct t_udf_file *newf;\n"
" newf = malloc(sizeof(*newf));\n"
" if (!newf) return 0;\n"
" if (!newf) {};\n"
"}");
ASSERT_EQUALS("", errout.str());
@ -4149,6 +4149,12 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("int* f() {\n"
" int *p = (int*)malloc(40);\n"
" return p;\n"
"}");
ASSERT_EQUALS("", errout.str());
// function parameter (treat it as initialized until malloc is used)
checkUninitVar("int f(int *p) {\n"
" if (*p == 1) {}\n" // no error