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, ("!|==|!=|<|<=|>|>= " + structname + " %varid% ==|!=|<|<=|>|>=|)|;").c_str(), varid) ||
|
||||||
Token::Match(tok3->previous(), "strlen|free ( %varid% )", 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())
|
if (!structname.empty())
|
||||||
{
|
{
|
||||||
tok3->deleteNext();
|
tok3->deleteNext();
|
||||||
|
|
|
@ -2052,6 +2052,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void simplifyKnownVariables42()
|
void simplifyKnownVariables42()
|
||||||
|
{
|
||||||
{
|
{
|
||||||
const char code[] = "void f() {\n"
|
const char code[] = "void f() {\n"
|
||||||
" char str1[10], str2[10];\n"
|
" char str1[10], str2[10];\n"
|
||||||
|
@ -2066,6 +2067,21 @@ private:
|
||||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
|
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()
|
void simplifyKnownVariablesBailOutAssign()
|
||||||
{
|
{
|
||||||
const char code[] = "int foo() {\n"
|
const char code[] = "int foo() {\n"
|
||||||
|
|
Loading…
Reference in New Issue