Fix 9953: false positive: uninitvar (#3548)
This commit is contained in:
parent
6338c2396c
commit
1791457227
|
@ -1317,42 +1317,6 @@ static void valueFlowPointerAlias(TokenList *tokenlist)
|
|||
}
|
||||
}
|
||||
|
||||
static void valueFlowUninitPointerAliasDeref(TokenList *tokenlist)
|
||||
{
|
||||
for (Token *tok = tokenlist->front(); tok; tok = tok->next()) {
|
||||
if (!tok->isUnaryOp("*"))
|
||||
continue;
|
||||
if (!astIsPointer(tok->astOperand1()))
|
||||
continue;
|
||||
|
||||
const Token* lifeTok = nullptr;
|
||||
ErrorPath errorPath;
|
||||
for (const ValueFlow::Value& v:tok->astOperand1()->values()) {
|
||||
if (!v.isLocalLifetimeValue())
|
||||
continue;
|
||||
lifeTok = v.tokvalue;
|
||||
errorPath = v.errorPath;
|
||||
}
|
||||
if (!lifeTok)
|
||||
continue;
|
||||
if (lifeTok->varId() == 0)
|
||||
continue;
|
||||
const Variable * var = lifeTok->variable();
|
||||
if (!var)
|
||||
continue;
|
||||
if (!var->isConst() && isVariableChanged(lifeTok->next(), tok, lifeTok->varId(), !var->isLocal(), tokenlist->getSettings(), tokenlist->isCPP()))
|
||||
continue;
|
||||
for (const ValueFlow::Value& v:lifeTok->values()) {
|
||||
// Forward uninit values since not all values can be forwarded directly
|
||||
if (!v.isUninitValue())
|
||||
continue;
|
||||
ValueFlow::Value value = v;
|
||||
value.errorPath.insert(value.errorPath.begin(), errorPath.begin(), errorPath.end());
|
||||
setTokenValue(tok, value, tokenlist->getSettings());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void valueFlowBitAnd(TokenList *tokenlist)
|
||||
{
|
||||
for (Token *tok = tokenlist->front(); tok; tok = tok->next()) {
|
||||
|
@ -7698,7 +7662,6 @@ void ValueFlow::setValues(TokenList *tokenlist, SymbolDatabase* symboldatabase,
|
|||
valueFlowLifetime(tokenlist, symboldatabase, errorLogger, settings);
|
||||
valueFlowFunctionDefaultParameter(tokenlist, symboldatabase, settings);
|
||||
valueFlowUninit(tokenlist, symboldatabase, settings);
|
||||
valueFlowUninitPointerAliasDeref(tokenlist);
|
||||
if (tokenlist->isCPP()) {
|
||||
valueFlowAfterMove(tokenlist, symboldatabase, settings);
|
||||
valueFlowSmartPointer(tokenlist, errorLogger, settings);
|
||||
|
|
|
@ -5358,6 +5358,14 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:2]: (error) Uninitialized variable: *buflen\n", errout.str());
|
||||
|
||||
// # 9953
|
||||
valueFlowUninit("uint32_t f(uint8_t *mem) {\n"
|
||||
" uint32_t u32;\n"
|
||||
" uint8_t *buf = (uint8_t *)(&u32);\n"
|
||||
" buf[0] = mem[0];\n"
|
||||
" return(*(uint32_t *)buf);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void valueFlowUninitStructMembers()
|
||||
|
@ -5427,7 +5435,7 @@ private:
|
|||
" x = *(&ab);\n"
|
||||
"}\n",
|
||||
"test.c");
|
||||
ASSERT_EQUALS("[test.c:5] -> [test.c:5]: (error) Uninitialized variable: *(&ab).b\n", errout.str());
|
||||
ASSERT_EQUALS("[test.c:5]: (error) Uninitialized variable: *(&ab).b\n", errout.str());
|
||||
|
||||
valueFlowUninit("void f(void) {\n"
|
||||
" struct AB ab;\n"
|
||||
|
|
Loading…
Reference in New Issue