Fixed #8172 (False positive uninitvar on sizeof *ptr)
This commit is contained in:
parent
f10634c021
commit
d160d27417
|
@ -1235,6 +1235,10 @@ void CheckUninitVar::valueFlowUninit()
|
||||||
if (!scope->isExecutable())
|
if (!scope->isExecutable())
|
||||||
continue;
|
continue;
|
||||||
for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
|
for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
|
||||||
|
if (Token::simpleMatch(tok, "sizeof (")) {
|
||||||
|
tok = tok->linkAt(1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!tok->variable() || tok->values().size() != 1U)
|
if (!tok->variable() || tok->values().size() != 1U)
|
||||||
continue;
|
continue;
|
||||||
const ValueFlow::Value &v = tok->values().front();
|
const ValueFlow::Value &v = tok->values().front();
|
||||||
|
|
|
@ -91,7 +91,6 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
settings.experimental = true;
|
|
||||||
settings.debugwarnings = debugwarnings;
|
settings.debugwarnings = debugwarnings;
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
|
@ -3823,18 +3822,44 @@ private:
|
||||||
check.deadPointer();
|
check.deadPointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void valueFlowUninit(const char code[]) {
|
||||||
|
// Clear the error buffer..
|
||||||
|
errout.str("");
|
||||||
|
|
||||||
|
// Tokenize..
|
||||||
|
settings.debugwarnings = false;
|
||||||
|
settings.experimental = false;
|
||||||
|
|
||||||
|
Tokenizer tokenizer(&settings, this);
|
||||||
|
std::istringstream istr(code);
|
||||||
|
tokenizer.tokenize(istr, "test.cpp");
|
||||||
|
|
||||||
|
tokenizer.simplifyTokenList2();
|
||||||
|
|
||||||
|
// Check for redundant code..
|
||||||
|
CheckUninitVar checkuninitvar(&tokenizer, &settings, this);
|
||||||
|
checkuninitvar.valueFlowUninit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void valueFlowUninit() {
|
void valueFlowUninit() {
|
||||||
checkUninitVar("void f() {\n"
|
valueFlowUninit("void f() {\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
" switch (x) {}\n"
|
" switch (x) {}\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout.str());
|
||||||
|
|
||||||
checkUninitVar("int f() {\n"
|
valueFlowUninit("int f() {\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
" init(x);\n"
|
" init(x);\n"
|
||||||
" return x;\n" // TODO: inconclusive ?
|
" return x;\n" // TODO: inconclusive ?
|
||||||
"}");
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
valueFlowUninit("void f() {\n" // #8172
|
||||||
|
" char **x;\n"
|
||||||
|
" if (2 < sizeof(*x)) {}\n"
|
||||||
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue