parent
d928b57829
commit
2b13a27140
|
@ -1263,8 +1263,13 @@ const Token* CheckUninitVar::isVariableUsage(bool cpp, const Token *vartok, cons
|
||||||
if (isLikelyStreamRead(cpp, vartok->previous()))
|
if (isLikelyStreamRead(cpp, vartok->previous()))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
if (valueExpr->valueType() && valueExpr->valueType()->type == ValueType::Type::VOID)
|
if (const auto* vt = valueExpr->valueType()) {
|
||||||
return nullptr;
|
if (vt->type == ValueType::Type::VOID)
|
||||||
|
return nullptr;
|
||||||
|
// passing a char* to a stream will dereference it
|
||||||
|
if ((alloc == CTOR_CALL || alloc == ARRAY) && vt->pointer && vt->type != ValueType::Type::CHAR && vt->type != ValueType::Type::WCHAR_T)
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (astIsRhs(derefValue) && isLikelyStreamRead(cpp, derefValue->astParent()))
|
if (astIsRhs(derefValue) && isLikelyStreamRead(cpp, derefValue->astParent()))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -525,6 +525,24 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Memory is allocated but not initialized: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Memory is allocated but not initialized: p\n", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("void f() {\n" // #9696
|
||||||
|
" int *p = new int[10];\n"
|
||||||
|
" std::cout << p << 1;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("void f() {\n"
|
||||||
|
" int i[10];\n"
|
||||||
|
" std::cout << i;\n"
|
||||||
|
" char c[10];\n"
|
||||||
|
" std::cout << c;\n"
|
||||||
|
" wchar_t w[10];\n"
|
||||||
|
" std::cout << w;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: c\n"
|
||||||
|
"[test.cpp:7]: (error) Uninitialized variable: w\n",
|
||||||
|
errout.str());
|
||||||
|
|
||||||
checkUninitVar("void f() {\n"
|
checkUninitVar("void f() {\n"
|
||||||
" char p[10];\n"
|
" char p[10];\n"
|
||||||
" std::cout << p << 1;\n"
|
" std::cout << p << 1;\n"
|
||||||
|
|
Loading…
Reference in New Issue