Fixed #7293 (Use of uninitialized pointer not detected (worked in 1.71))
This commit is contained in:
parent
6b685f5a80
commit
37fd60e879
|
@ -2849,16 +2849,18 @@ static void valueFlowUninit(TokenList *tokenlist, SymbolDatabase * /*symbolDatab
|
|||
continue;
|
||||
const Token *vardecl = tok->next();
|
||||
bool stdtype = false;
|
||||
bool pointer = false;
|
||||
while (Token::Match(vardecl, "%name%|::|*") && vardecl->varId() == 0) {
|
||||
stdtype |= vardecl->isStandardType();
|
||||
pointer |= vardecl->str() == "*";
|
||||
vardecl = vardecl->next();
|
||||
}
|
||||
if (!tokenlist->isC() && !stdtype && !pointer)
|
||||
continue;
|
||||
if (!Token::Match(vardecl, "%var% ;"))
|
||||
continue;
|
||||
if (Token::Match(vardecl, "%varid% ; %varid% =", vardecl->varId()))
|
||||
continue;
|
||||
if (!tokenlist->isC() && !stdtype)
|
||||
continue;
|
||||
const Variable *var = vardecl->variable();
|
||||
if (!var || var->nameToken() != vardecl)
|
||||
continue;
|
||||
|
|
|
@ -441,7 +441,7 @@ private:
|
|||
|
||||
// #2641 - local pointer, function call
|
||||
check("void f() {\n"
|
||||
" ABC *abc;\n"
|
||||
" ABC *abc = abc1;\n"
|
||||
" abc->a = 0;\n"
|
||||
" do_stuff();\n"
|
||||
" if (abc) { }\n"
|
||||
|
|
|
@ -2377,16 +2377,22 @@ private:
|
|||
}
|
||||
|
||||
void valueFlowUninit() {
|
||||
const char* code;
|
||||
std::list<ValueFlow::Value> values;
|
||||
|
||||
const char* code = "void f() {\n"
|
||||
" int x;\n"
|
||||
" switch (x) {}\n"
|
||||
"}";
|
||||
|
||||
code = "void f() {\n"
|
||||
" int x;\n"
|
||||
" switch (x) {}\n"
|
||||
"}";
|
||||
values = tokenValues(code, "x )");
|
||||
ASSERT_EQUALS(1U, values.size());
|
||||
ASSERT_EQUALS(ValueFlow::Value::UNINIT, values.empty() ? 0 : values.front().valueType);
|
||||
ASSERT_EQUALS(true, values.size()==1U && values.front().isUninitValue());
|
||||
|
||||
code = "void f() {\n"
|
||||
" C *c;\n"
|
||||
" if (c->x() == 4) {}\n"
|
||||
"}";
|
||||
values = tokenValues(code, "c .");
|
||||
ASSERT_EQUALS(true, values.size()==1U && values.front().isUninitValue());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue