Fixed #3708 (False positive: uninitialized variable (allocation, unknown nonpointer type))

This commit is contained in:
Daniel Marjamäki 2012-05-14 18:34:39 +02:00
parent 8a7b141246
commit fc7f78244e
2 changed files with 14 additions and 2 deletions

View File

@ -91,8 +91,13 @@ private:
std::list<ExecutionPath *>::const_iterator it;
for (it = checks.begin(); it != checks.end(); ++it) {
UninitVar *c = dynamic_cast<UninitVar *>(*it);
if (c && c->varId == varid)
c->alloc = true;
if (c && c->varId == varid) {
if (c->pointer)
c->alloc = true;
else
bailOutVar(checks, varid);
break;
}
}
}

View File

@ -1300,6 +1300,13 @@ private:
" char c = *s;\n"
"};\n");
ASSERT_EQUALS("[test.cpp:6]: (error) Data is allocated but not initialized: s\n", errout.str());
// #3708 - false positive when using ptr typedef
checkUninitVar("void f() {\n"
" uintptr_t x = malloc(100);\n"
" uintptr_t y = x + 10;\n" // <- not bad usage
"}\n");
ASSERT_EQUALS("", errout.str());
}
// class / struct..