Fixed #3500 (false negative: (error) Returning pointer to local array variable)
This commit is contained in:
parent
f1c195e652
commit
bff6ed7af0
|
@ -7588,7 +7588,10 @@ bool Tokenizer::isFunctionParameterPassedByValue(const Token *fpar) const
|
|||
|
||||
// Is this a function call?
|
||||
if (ftok && Token::Match(ftok->tokAt(-2), "[;{}=] %var% (")) {
|
||||
const std::string functionName(ftok->previous()->str() + " (");
|
||||
const std::string functionName(ftok->previous()->str());
|
||||
|
||||
if (functionName == "return")
|
||||
return true;
|
||||
|
||||
// Locate function declaration..
|
||||
unsigned int indentlevel = 0;
|
||||
|
@ -7597,7 +7600,7 @@ bool Tokenizer::isFunctionParameterPassedByValue(const Token *fpar) const
|
|||
++indentlevel;
|
||||
else if (tok->str() == "}")
|
||||
indentlevel = (indentlevel > 0) ? indentlevel - 1U : 0U;
|
||||
else if (indentlevel == 0 && tok->isName() && Token::simpleMatch(tok, functionName.c_str())) {
|
||||
else if (indentlevel == 0 && Token::Match(tok, "%type% (") && tok->str() == functionName) {
|
||||
// Goto parameter
|
||||
tok = tok->tokAt(2);
|
||||
unsigned int par = 1;
|
||||
|
|
|
@ -180,6 +180,7 @@ private:
|
|||
TEST_CASE(simplifyKnownVariablesFloat); // #2454 - float variable
|
||||
TEST_CASE(simplifyKnownVariablesClassMember); // #2815 - value of class member may be changed by function call
|
||||
TEST_CASE(simplifyKnownVariablesFunctionCalls); // Function calls (don't assume pass by reference)
|
||||
TEST_CASE(simplifyKnownVariablesReturn); // 3500 - return
|
||||
TEST_CASE(simplifyExternC);
|
||||
|
||||
TEST_CASE(varid1);
|
||||
|
@ -2782,6 +2783,14 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
void simplifyKnownVariablesReturn() {
|
||||
const char code[] = "int a() {"
|
||||
" int x = 123;"
|
||||
" return (x);"
|
||||
"}";
|
||||
ASSERT_EQUALS("int a ( ) { return 123 ; }", tokenizeAndStringify(code,true));
|
||||
}
|
||||
|
||||
void simplifyKnownVariablesClassMember() {
|
||||
// Ticket #2815
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue