Fixed #5666 (False positive when modifiying std::string by pointer)
This commit is contained in:
parent
7e7aa21029
commit
1b21767954
|
@ -6249,7 +6249,7 @@ bool Tokenizer::simplifyKnownVariables()
|
|||
(Token::Match(tok2, "%name% = %bool%|%char%|%num%|%str%|%name% ;") ||
|
||||
Token::Match(tok2, "%name% [ %num%| ] = %str% ;") ||
|
||||
Token::Match(tok2, "%name% = & %name% ;") ||
|
||||
Token::Match(tok2, "%name% = & %name% [ 0 ] ;"))) {
|
||||
(Token::Match(tok2, "%name% = & %name% [ 0 ] ;") && arrays.find(tok2->tokAt(3)->varId()) != arrays.end()))) {
|
||||
const unsigned int varid = tok2->varId();
|
||||
if (varid == 0)
|
||||
continue;
|
||||
|
|
|
@ -179,6 +179,7 @@ private:
|
|||
TEST_CASE(simplifyKnownVariables59); // skip for header
|
||||
TEST_CASE(simplifyKnownVariables60); // #6829
|
||||
TEST_CASE(simplifyKnownVariables61); // #7805
|
||||
TEST_CASE(simplifyKnownVariables62); // #5666 - p=&str[0]
|
||||
TEST_CASE(simplifyKnownVariablesBailOutAssign1);
|
||||
TEST_CASE(simplifyKnownVariablesBailOutAssign2);
|
||||
TEST_CASE(simplifyKnownVariablesBailOutAssign3); // #4395 - nested assignments
|
||||
|
@ -2663,6 +2664,17 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void simplifyKnownVariables62() { // #5666
|
||||
ASSERT_EQUALS("void foo ( std :: string str ) {\n"
|
||||
"char * p ; p = & str [ 0 ] ;\n"
|
||||
"* p = 0 ;\n"
|
||||
"}",
|
||||
tokenizeAndStringify("void foo(std::string str) {\n"
|
||||
" char *p = &str[0];\n"
|
||||
" *p = 0;\n"
|
||||
"}", /*simplify=*/true));
|
||||
}
|
||||
|
||||
void simplifyKnownVariablesBailOutAssign1() {
|
||||
const char code[] = "int foo() {\n"
|
||||
" int i; i = 0;\n"
|
||||
|
|
Loading…
Reference in New Issue