UninitVar: Fixed false positive when checking if allocated pointer is null
This commit is contained in:
parent
4c44e62159
commit
26dfddac6b
|
@ -1812,7 +1812,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
|
||||||
return (var && var->typeStartToken()->isStandardType());
|
return (var && var->typeStartToken()->isStandardType());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vartok->next() && vartok->next()->isOp() && !vartok->next()->isAssignmentOp())
|
if (!alloc && vartok->next() && vartok->next()->isOp() && !vartok->next()->isAssignmentOp())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (vartok->strAt(1) == "]")
|
if (vartok->strAt(1) == "]")
|
||||||
|
|
|
@ -3342,6 +3342,12 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar2("void f() {\n"
|
||||||
|
" char *p = malloc(100);\n"
|
||||||
|
" p || assert_failed();\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// function parameter (treat it as initialized until malloc is used)
|
// function parameter (treat it as initialized until malloc is used)
|
||||||
checkUninitVar2("int f(int *p) {\n"
|
checkUninitVar2("int f(int *p) {\n"
|
||||||
" if (*p == 1) {}\n" // no error
|
" if (*p == 1) {}\n" // no error
|
||||||
|
|
Loading…
Reference in New Issue