diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index cfcd72660..a1eadd926 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3966,7 +3966,7 @@ bool Tokenizer::simplifyKnownVariables() ret = true; } - if (Token::Match(tok3->next(), "++|-- %varid%", varid) && + if (Token::Match(tok3->next(), "++|-- %varid%", varid) && MathLib::isInt(value) && !Token::Match(tok3->tokAt(3), "[.[]")) { incdec(value, tok3->strAt(1)); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 003ca427c..4eeadad15 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -89,6 +89,7 @@ private: TEST_CASE(simplifyKnownVariables15); TEST_CASE(simplifyKnownVariables16); TEST_CASE(simplifyKnownVariables17); + TEST_CASE(simplifyKnownVariables18); TEST_CASE(match1); @@ -957,6 +958,14 @@ private: simplifyKnownVariables(code)); } + void simplifyKnownVariables18() + { + 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%"