Skip to content

Commit 61d83ea

Browse files
Fix #11290 FP uninitdata with array member (#8464)
1 parent ef91022 commit 61d83ea

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

lib/checkuninitvar.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,8 @@ int CheckUninitVar::isFunctionParUsage(const Token *vartok, const Library& libra
14221422
const bool isnullbad = library.isnullargbad(start->previous(), argumentNumber + 1);
14231423
if (indirect == 0 && pointer && !address && isnullbad && alloc == NO_ALLOC)
14241424
return 1;
1425+
if (vartok->varId() == 0 && vartok->valueType())
1426+
indirect = vartok->valueType()->pointer;
14251427
bool hasIndirect = false;
14261428
const bool isuninitbad = library.isuninitargbad(start->previous(), argumentNumber + 1, indirect, &hasIndirect);
14271429
if (alloc != NO_ALLOC)

test/testuninitvar.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,14 @@ class TestUninitVar : public TestFixture {
21732173
" return p;\n"
21742174
"}\n");
21752175
ASSERT_EQUALS("", errout_str());
2176+
2177+
checkUninitVar("struct S { char c[10]; };\n" // #11290
2178+
"S* f() {\n"
2179+
" S* s = (S*)malloc(sizeof(S));\n"
2180+
" sprintf(s->c, \"abc\");\n"
2181+
" return s;\n"
2182+
"}\n");
2183+
ASSERT_EQUALS("", errout_str());
21762184
}
21772185

21782186
// class / struct..

0 commit comments

Comments
 (0)