From 7fc72484ecb51cd1e5524b653c04e646175b28c1 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Tue, 3 Nov 2009 00:07:15 +0200 Subject: [PATCH] Fix #881 (Tokenizer: Something seems to be wrong in Tokenizer::simplifyKnownVariables) http://sourceforge.net/apps/trac/cppcheck/ticket/881 --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index fc9d8d0f0..48f746b73 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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% ;")) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index d574f9fd6..85d520149 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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%"