From acdbbeee44f9c3cb3c6489bed9f51cbfd9658bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 25 Aug 2013 08:54:33 +0200 Subject: [PATCH] Fixed #4913 (Tokenizer::simplifyKnownVariables: wrong handling of *--p=0;) --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b5a1119af..51f49904b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6170,7 +6170,7 @@ bool Tokenizer::simplifyKnownVariables() break; } - else if (tok2->previous()->str() != "*" && + else if (tok2->previous()->str() != "*" && !Token::Match(tok2->tokAt(-2), "* --|++") && (Token::Match(tok2, "%var% = %bool%|%char%|%num%|%str%|%var% ;") || Token::Match(tok2, "%var% [ ] = %str% ;") || Token::Match(tok2, "%var% [ %num% ] = %str% ;") || diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 391eba596..0f1620ae0 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -176,6 +176,7 @@ private: TEST_CASE(simplifyKnownVariables51); // #4409 hang TEST_CASE(simplifyKnownVariables52); // #4728 "= x %cop%" TEST_CASE(simplifyKnownVariables53); // references + TEST_CASE(simplifyKnownVariables54); // #4913 'x' is not 0 after *--x=0; TEST_CASE(simplifyKnownVariablesIfEq1); // if (a==5) => a is 5 in the block TEST_CASE(simplifyKnownVariablesIfEq2); // if (a==5) { buf[a++] = 0; } TEST_CASE(simplifyKnownVariablesIfEq3); // #4708 - if (a==5) { buf[--a] = 0; } @@ -2732,6 +2733,10 @@ private: ASSERT_EQUALS("void f ( ) { int * p ; p = abc ( ) ; }", tokenizeAndStringify("void f() { int *p; int *&ref=p; ref=abc(); }", true)); } + void simplifyKnownVariables54() { // #4913 + ASSERT_EQUALS("void f ( int * p ) { * -- p = 0 ; * p = 0 ; }", tokenizeAndStringify("void f(int*p) { *--p=0; *p=0; }", true)); + } + void simplifyKnownVariablesIfEq1() { const char code[] = "void f(int x) {\n" " if (x==5) {\n"