Permalink
Browse files

Fixed #7293 (Use of uninitialized pointer not detected (worked in 1.71))

1 parent 6b685f5 commit 37fd60e87927ed32f3f66bb2d00e53667d08bf34 @danmar committed Apr 24, 2017
Showing with 18 additions and 10 deletions.
  1. +4 −2 lib/valueflow.cpp
  2. +1 −1 test/testnullpointer.cpp
  3. +13 −7 test/testvalueflow.cpp
View
@@ -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;
View
@@ -441,7 +441,7 @@ class TestNullPointer : public TestFixture {
// #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"
View
@@ -2377,16 +2377,22 @@ class TestValueFlow : public TestFixture {
}
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());
}
};

0 comments on commit 37fd60e

Please sign in to comment.