Fixed #972 (New check: return pointer of stack memory)

This commit is contained in:
Daniel Marjamäki 2009-12-27 13:08:41 +01:00
parent dccba65502
commit c7cede1d76
2 changed files with 24 additions and 0 deletions

View File

@ -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);
}
}
}
}

View File

@ -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));
}
}