From 0425f1d46d834afd98d039d06d1fcfd6ebec0423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 16 Oct 2017 17:39:50 +0200 Subject: [PATCH] Fixed #8241 (FP: Same expression on both sides of operator) --- lib/tokenize.cpp | 3 +++ test/testtokenize.cpp | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index cdf5e563d..ca41cbbb5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5248,6 +5248,9 @@ void Tokenizer::simplifyPointerToStandardType() if (!Token::Match(tok, "& %name% [ 0 ] !![")) continue; + if (!Token::Match(tok->previous(), "[,(=]")) + continue; + // Remove '[ 0 ]' suffix tok->next()->eraseTokens(tok->next(), tok->tokAt(5)); // Remove '&' prefix diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 0eab14217..ad7133e61 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4712,6 +4712,10 @@ private: tokenizeAndStringify("char buf[100] ; readlink(path, &buf[0], 99);", false, true, Settings::Native, "test.c")); + ASSERT_EQUALS("void foo ( char * c ) { if ( 1 == ( 1 & c [ 0 ] ) ) { } }", + tokenizeAndStringify("void foo(char *c) { if (1==(1 & c[0])) {} }", + false, true, Settings::Native, "test.c")); + // Simplification of unknown type - C only ASSERT_EQUALS("foo data [ 100 ] ; something ( foo ) ;", tokenizeAndStringify("foo data[100]; something(&foo[0]);", false, true, Settings::Native, "test.c"));