Fix #881 (Tokenizer: Something seems to be wrong in Tokenizer::simplifyKnownVariables)

http://sourceforge.net/apps/trac/cppcheck/ticket/881
This commit is contained in:
Reijo Tomperi 2009-11-03 00:07:15 +02:00
parent 87800185c4
commit 7fc72484ec
2 changed files with 11 additions and 1 deletions

View File

@ -3461,7 +3461,7 @@ bool Tokenizer::simplifyKnownVariables()
ret = true;
}
if (Token::Match(tok3->next(), "%varid% ++|--", varid))
if (Token::Match(tok3->next(), "%varid% ++|--", varid) && MathLib::isInt(value))
{
const std::string op(tok3->strAt(2));
if (Token::Match(tok3, "[{};] %any% %any% ;"))

View File

@ -82,6 +82,7 @@ private:
TEST_CASE(simplifyKnownVariables14);
TEST_CASE(simplifyKnownVariables15);
TEST_CASE(simplifyKnownVariables16);
TEST_CASE(simplifyKnownVariables17);
TEST_CASE(match1);
@ -837,6 +838,15 @@ private:
simplifyKnownVariables(code);
}
void simplifyKnownVariables17()
{
// ticket #807 - segmentation fault when macro isn't found
const char code[] = "void f ( ) { char *s = malloc(100);mp_ptr p = s; p++; }";
ASSERT_EQUALS(
"void f ( ) { char * s ; s = malloc ( 100 ) ; mp_ptr p ; p = s ; p ++ ; }",
simplifyKnownVariables(code));
}
void match1()
{
// Match "%var% | %var%"