Fixed #2618 (Tokenizer::simplifyKnownVariables: Don't use known string value if address is wanted)
This commit is contained in:
parent
db04d7b71e
commit
8e9a1c33ad
|
@ -6636,6 +6636,12 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
|||
Token::Match(tok3, ("!|==|!=|<|<=|>|>= " + structname + " %varid% ==|!=|<|<=|>|>=|)|;").c_str(), varid) ||
|
||||
Token::Match(tok3->previous(), "strlen|free ( %varid% )", varid))
|
||||
{
|
||||
if (value[0] == '\"' && tok3->strAt(-1) != "strlen")
|
||||
{
|
||||
// bail out if value is a string unless if it's just given
|
||||
// as parameter to strlen
|
||||
break;
|
||||
}
|
||||
if (!structname.empty())
|
||||
{
|
||||
tok3->deleteNext();
|
||||
|
|
|
@ -2053,17 +2053,33 @@ private:
|
|||
|
||||
void simplifyKnownVariables42()
|
||||
{
|
||||
const char code[] = "void f() {\n"
|
||||
" char str1[10], str2[10];\n"
|
||||
" strcpy(str1, \"abc\");\n"
|
||||
" strcpy(str2, str1);\n"
|
||||
"}";
|
||||
const char expected[] = "void f ( ) {\n"
|
||||
"char str1 [ 10 ] ; char str2 [ 10 ] ;\n"
|
||||
"strcpy ( str1 , \"abc\" ) ;\n"
|
||||
"strcpy ( str2 , \"abc\" ) ;\n"
|
||||
{
|
||||
const char code[] = "void f() {\n"
|
||||
" char str1[10], str2[10];\n"
|
||||
" strcpy(str1, \"abc\");\n"
|
||||
" strcpy(str2, str1);\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
|
||||
const char expected[] = "void f ( ) {\n"
|
||||
"char str1 [ 10 ] ; char str2 [ 10 ] ;\n"
|
||||
"strcpy ( str1 , \"abc\" ) ;\n"
|
||||
"strcpy ( str2 , \"abc\" ) ;\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
|
||||
}
|
||||
|
||||
{
|
||||
const char code[] = "void f() {"
|
||||
" char *s = malloc(10);"
|
||||
" strcpy(s, \"\");"
|
||||
" free(s);"
|
||||
"}";
|
||||
const char expected[] = "void f ( ) {"
|
||||
" char * s ; s = malloc ( 10 ) ;"
|
||||
" strcpy ( s , \"\" ) ;"
|
||||
" free ( s ) ; "
|
||||
"}";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
|
||||
}
|
||||
}
|
||||
|
||||
void simplifyKnownVariablesBailOutAssign()
|
||||
|
|
Loading…
Reference in New Issue