Fixed #9933 (FP: uninitvar when reading to struct)

This commit is contained in:
Daniel Marjamäki 2020-11-11 22:47:23 +01:00
parent 2ae91b9ffe
commit 4330a43acb
2 changed files with 13 additions and 0 deletions

View File

@ -1368,6 +1368,8 @@ const Token * getTokenArgumentFunction(const Token * tok, int& argn)
parent = parent->astParent(); parent = parent->astParent();
while (parent && parent->isCast()) while (parent && parent->isCast())
parent = parent->astParent(); parent = parent->astParent();
if (Token::Match(parent, "[+-]") && parent->valueType() && parent->valueType()->pointer)
parent = parent->astParent();
// passing variable to subfunction? // passing variable to subfunction?
if (Token::Match(parent, "[(,{]")) if (Token::Match(parent, "[(,{]"))

View File

@ -4109,6 +4109,17 @@ private:
"}"; "}";
values = tokenValues(code, "szHdr ; }"); values = tokenValues(code, "szHdr ; }");
ASSERT_EQUALS(0, values.size()); ASSERT_EQUALS(0, values.size());
// #9933
code = "struct MyStruct { size_t value; }\n"
"\n"
"void foo() {\n"
" MyStruct x;\n"
" fread(((char *)&x) + 0, sizeof(x), f);\n"
" if (x.value < 432) {}\n"
"}";
values = tokenValues(code, "x . value");
ASSERT_EQUALS(0, values.size());
} }
void valueFlowTerminatingCond() { void valueFlowTerminatingCond() {