From 11bd6bcd30ee2addd89e1dec7e60fe6b6eae0792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 10 Apr 2011 21:27:09 +0200 Subject: [PATCH] Fixed #2712 (false positive: Division by zero) --- lib/tokenize.cpp | 4 ++-- test/testsimplifytokens.cpp | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 627544009..df176c3a0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7394,9 +7394,9 @@ bool Tokenizer::simplifyCalculations() // + and - are calculated after * and / else if (Token::Match(tok->next(), "[+-/]")) { - if (tok->previous()->str() == "*") + if (Token::Match(tok->previous(), "[*/%]")) continue; - if (Token::Match(tok->tokAt(3), "[*/]")) + if (Token::Match(tok->tokAt(3), "[*/%]")) continue; } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 329fa0276..82a18ca89 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -2723,6 +2723,9 @@ private: ASSERT_EQUALS("if ( a == 2 )", tok("if (a==1+1)")); ASSERT_EQUALS("if ( a + 2 != 6 )", tok("if (a+1+1!=1+2+3)")); ASSERT_EQUALS("if ( 4 < a )", tok("if (14-2*5