Fixed #2117 (false positive: buffer access out of bounds)
This commit is contained in:
parent
2346ab8839
commit
9fdc03fc1d
|
@ -1174,7 +1174,9 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
|
|||
varid = tok->tokAt(1)->varId();
|
||||
nextTok = 8;
|
||||
}
|
||||
else if (indentlevel > 0 && Token::Match(tok, "[;{}] %var% = %str% ;"))
|
||||
else if (indentlevel > 0 &&
|
||||
Token::Match(tok, "[;{}] %var% = %str% ;") &&
|
||||
NULL != Token::findmatch(_tokenizer->tokens(), "[;{}] const| %type% * %varid% ;", tok->next()->varId()))
|
||||
{
|
||||
size = 1 + int(tok->tokAt(3)->strValue().size());
|
||||
type = "char";
|
||||
|
|
|
@ -137,6 +137,7 @@ private:
|
|||
TEST_CASE(sprintf7);
|
||||
TEST_CASE(sprintf8);
|
||||
TEST_CASE(sprintf9);
|
||||
TEST_CASE(sprintf10);
|
||||
|
||||
TEST_CASE(snprintf1);
|
||||
TEST_CASE(snprintf2);
|
||||
|
@ -1835,6 +1836,16 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void sprintf10()
|
||||
{
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" TString str = \"\";\n"
|
||||
" sprintf(str, \"1\");\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void snprintf1()
|
||||
{
|
||||
check("void f()\n"
|
||||
|
|
Loading…
Reference in New Issue