Fixed #3538 (false positive caused by bad tokenizer simplification)
This commit is contained in:
parent
036b2a84bf
commit
2be85e9d37
|
@ -6494,7 +6494,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
||||||
}
|
}
|
||||||
|
|
||||||
// array usage
|
// array usage
|
||||||
if (Token::Match(tok3, ("[(,] " + structname + " %varid% [|%op%").c_str(), varid)) {
|
if (value[0] != '\"' && Token::Match(tok3, ("[(,] " + structname + " %varid% [|%op%").c_str(), varid)) {
|
||||||
if (!structname.empty()) {
|
if (!structname.empty()) {
|
||||||
tok3->deleteNext(2);
|
tok3->deleteNext(2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1773,14 +1773,14 @@ private:
|
||||||
" int i = 10;\n"
|
" int i = 10;\n"
|
||||||
" bar(str[i]);\n"
|
" bar(str[i]);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Buffer access out-of-bounds: \"abc\"\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'str[4]' index 10 out of bounds\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" const char *str = \"abc\";\n"
|
" const char *str = \"abc\";\n"
|
||||||
" bar(str[4]);\n"
|
" bar(str[4]);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds: \"abc\"\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[4]' index 4 out of bounds\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1794,7 +1794,7 @@ private:
|
||||||
" const char *str = \"a\tc\";\n"
|
" const char *str = \"a\tc\";\n"
|
||||||
" bar(str[4]);\n"
|
" bar(str[4]);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds: \"a\tc\"\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'str[4]' index 4 out of bounds\n", errout.str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2195,6 +2195,21 @@ private:
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
|
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3538
|
||||||
|
{
|
||||||
|
const char code[] = "void f() {\n"
|
||||||
|
" char s[10];\n"
|
||||||
|
" strcpy(s, \"123\");\n"
|
||||||
|
" if (s[6] == ' ');\n"
|
||||||
|
"}";
|
||||||
|
const char expected[] = "void f ( ) {\n"
|
||||||
|
"char s [ 10 ] ;\n"
|
||||||
|
"strcpy ( s , \"123\" ) ;\n"
|
||||||
|
"if ( s [ 6 ] == ' ' ) { ; }\n"
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS(expected, tokenizeAndStringify(code,true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void simplifyKnownVariables43() {
|
void simplifyKnownVariables43() {
|
||||||
|
|
Loading…
Reference in New Issue