Fix 10553: FP uninitvar with strcpy (#3652)
This commit is contained in:
parent
e6ccf299b9
commit
d36aa590cd
|
@ -2017,6 +2017,17 @@ static bool isTrivialConstructor(const Token* tok)
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool isArray(const Token* tok)
|
||||
{
|
||||
if (!tok)
|
||||
return false;
|
||||
if (tok->variable())
|
||||
return tok->variable()->isArray();
|
||||
if (Token::simpleMatch(tok, "."))
|
||||
return isArray(tok->astOperand2());
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Settings *settings, bool *inconclusive)
|
||||
{
|
||||
if (!tok)
|
||||
|
@ -2056,7 +2067,7 @@ bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Setti
|
|||
argDirection == Library::ArgumentChecks::Direction::DIR_INOUT) {
|
||||
// With out or inout the direction of the content is specified, not a pointer itself, so ignore pointers for now
|
||||
const ValueType * const valueType = tok1->valueType();
|
||||
if (valueType && valueType->pointer == indirect) {
|
||||
if ((valueType && valueType->pointer == indirect) || (indirect == 0 && isArray(tok1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5129,6 +5129,17 @@ private:
|
|||
" return rez;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #10553
|
||||
valueFlowUninit("struct CharDataOnly {\n"
|
||||
" char data[100];\n"
|
||||
"};\n"
|
||||
"CharDataOnly f() {\n"
|
||||
" CharDataOnly testData;\n"
|
||||
" strcpy(testData.data, \"string smaller than size\");\n"
|
||||
" return testData;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value
|
||||
|
|
Loading…
Reference in New Issue