uninitialized variables: better checking of strncpy
This commit is contained in:
parent
d70bc2359a
commit
c561a36cc7
|
@ -1314,6 +1314,11 @@ static const Token *uninitvar_checkscope(const Token * const tokens, const Token
|
|||
return tok->tokAt(4);
|
||||
if (Token::Match(tok, "strcat|strncat ( %varid% ,", varid))
|
||||
return tok->tokAt(3);
|
||||
if (Token::Match(tok, "strncpy ( %varid%", varid))
|
||||
{
|
||||
tok = tok->tokAt(3);
|
||||
continue;
|
||||
}
|
||||
if (Token::Match(tok, "asm ( )"))
|
||||
{
|
||||
init = true;
|
||||
|
|
|
@ -1128,6 +1128,14 @@ private:
|
|||
" strcat(s, \"abc\");\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str());
|
||||
|
||||
checkUninitVar("void f()\n"
|
||||
"{\n"
|
||||
" char s[20];\n"
|
||||
" strncpy(s, \"abcde\", 2);\n"
|
||||
" strcat(s, \"abc\");\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: s\n", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue