Fixed #972 (New check: return pointer of stack memory)
This commit is contained in:
parent
dccba65502
commit
c7cede1d76
|
@ -3769,6 +3769,12 @@ bool Tokenizer::simplifyKnownVariables()
|
|||
tok3 = tok3->next();
|
||||
ret = true;
|
||||
}
|
||||
|
||||
// return variable..
|
||||
if (Token::Match(tok3, "return %varid% ;", varid))
|
||||
{
|
||||
tok3->next()->str(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2473,6 +2473,24 @@ private:
|
|||
|
||||
ASSERT_EQUALS(expected, tok(code));
|
||||
}
|
||||
|
||||
{
|
||||
const char code[] = "int *foo()\n"
|
||||
"{\n"
|
||||
" int a[10];\n"
|
||||
" int *b = a;\n"
|
||||
" return b;\n"
|
||||
"}\n";
|
||||
|
||||
const char expected[] = "int * foo ( ) "
|
||||
"{ "
|
||||
"int a [ 10 ] ; "
|
||||
"int * b ; b = a ; "
|
||||
"return a ; "
|
||||
"}";
|
||||
|
||||
ASSERT_EQUALS(expected, tok(code));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue