Skip to content

Commit 1791457

Browse files
authored
Fix 9953: false positive: uninitvar (#3548)
1 parent 6338c23 commit 1791457

2 files changed

Lines changed: 9 additions & 38 deletions

File tree

lib/valueflow.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,42 +1317,6 @@ static void valueFlowPointerAlias(TokenList *tokenlist)
13171317
}
13181318
}
13191319

1320-
static void valueFlowUninitPointerAliasDeref(TokenList *tokenlist)
1321-
{
1322-
for (Token *tok = tokenlist->front(); tok; tok = tok->next()) {
1323-
if (!tok->isUnaryOp("*"))
1324-
continue;
1325-
if (!astIsPointer(tok->astOperand1()))
1326-
continue;
1327-
1328-
const Token* lifeTok = nullptr;
1329-
ErrorPath errorPath;
1330-
for (const ValueFlow::Value& v:tok->astOperand1()->values()) {
1331-
if (!v.isLocalLifetimeValue())
1332-
continue;
1333-
lifeTok = v.tokvalue;
1334-
errorPath = v.errorPath;
1335-
}
1336-
if (!lifeTok)
1337-
continue;
1338-
if (lifeTok->varId() == 0)
1339-
continue;
1340-
const Variable * var = lifeTok->variable();
1341-
if (!var)
1342-
continue;
1343-
if (!var->isConst() && isVariableChanged(lifeTok->next(), tok, lifeTok->varId(), !var->isLocal(), tokenlist->getSettings(), tokenlist->isCPP()))
1344-
continue;
1345-
for (const ValueFlow::Value& v:lifeTok->values()) {
1346-
// Forward uninit values since not all values can be forwarded directly
1347-
if (!v.isUninitValue())
1348-
continue;
1349-
ValueFlow::Value value = v;
1350-
value.errorPath.insert(value.errorPath.begin(), errorPath.begin(), errorPath.end());
1351-
setTokenValue(tok, value, tokenlist->getSettings());
1352-
}
1353-
}
1354-
}
1355-
13561320
static void valueFlowBitAnd(TokenList *tokenlist)
13571321
{
13581322
for (Token *tok = tokenlist->front(); tok; tok = tok->next()) {
@@ -7698,7 +7662,6 @@ void ValueFlow::setValues(TokenList *tokenlist, SymbolDatabase* symboldatabase,
76987662
valueFlowLifetime(tokenlist, symboldatabase, errorLogger, settings);
76997663
valueFlowFunctionDefaultParameter(tokenlist, symboldatabase, settings);
77007664
valueFlowUninit(tokenlist, symboldatabase, settings);
7701-
valueFlowUninitPointerAliasDeref(tokenlist);
77027665
if (tokenlist->isCPP()) {
77037666
valueFlowAfterMove(tokenlist, symboldatabase, settings);
77047667
valueFlowSmartPointer(tokenlist, errorLogger, settings);

test/testuninitvar.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5358,6 +5358,14 @@ class TestUninitVar : public TestFixture {
53585358
"}");
53595359
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:2]: (error) Uninitialized variable: *buflen\n", errout.str());
53605360

5361+
// # 9953
5362+
valueFlowUninit("uint32_t f(uint8_t *mem) {\n"
5363+
" uint32_t u32;\n"
5364+
" uint8_t *buf = (uint8_t *)(&u32);\n"
5365+
" buf[0] = mem[0];\n"
5366+
" return(*(uint32_t *)buf);\n"
5367+
"}\n");
5368+
ASSERT_EQUALS("", errout.str());
53615369
}
53625370

53635371
void valueFlowUninitStructMembers()
@@ -5427,7 +5435,7 @@ class TestUninitVar : public TestFixture {
54275435
" x = *(&ab);\n"
54285436
"}\n",
54295437
"test.c");
5430-
ASSERT_EQUALS("[test.c:5] -> [test.c:5]: (error) Uninitialized variable: *(&ab).b\n", errout.str());
5438+
ASSERT_EQUALS("[test.c:5]: (error) Uninitialized variable: *(&ab).b\n", errout.str());
54315439

54325440
valueFlowUninit("void f(void) {\n"
54335441
" struct AB ab;\n"

0 commit comments

Comments
 (0)