uninitialized variables: better checking of strncpy

This commit is contained in:
Daniel Marjamäki 2009-11-06 19:06:45 +01:00
parent d70bc2359a
commit c561a36cc7
2 changed files with 13 additions and 0 deletions

View File

@ -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;

View File

@ -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());
}