From cad4e4ab20eca4e46b107ba5bd200fd8c7a95ae1 Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Fri, 30 Nov 2018 13:53:58 +0100 Subject: [PATCH] Fix handling of `sizeof &var` (#1498) Fixes https://trac.cppcheck.net/ticket/8870 --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 9aad928d5..54937388c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3340,7 +3340,7 @@ void Tokenizer::sizeofAddParentheses() for (Token *tok = list.front(); tok; tok = tok->next()) { if (!Token::Match(tok, "sizeof !!(")) continue; - if (tok->next()->isLiteral() || Token::Match(tok->next(), "%name%|*|~|!")) { + if (tok->next()->isLiteral() || Token::Match(tok->next(), "%name%|*|~|!|&")) { Token *endToken = tok->next(); while (Token::simpleMatch(endToken, "* *")) endToken = endToken->next(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 199f026d0..759e0a297 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -8662,6 +8662,7 @@ private: ASSERT_EQUALS("sizeof ( a . b ) + 3 ;", tokenizeAndStringify("sizeof a.b+3;")); ASSERT_EQUALS("sizeof ( a [ 2 ] . b ) + 3 ;", tokenizeAndStringify("sizeof a[2].b+3;")); ASSERT_EQUALS("f ( 0 , sizeof ( ptr . bar ) ) ;", tokenizeAndStringify("f(0, sizeof ptr->bar );")); + ASSERT_EQUALS("sizeof ( a ) > sizeof ( & main ) ;", tokenizeAndStringify("sizeof a > sizeof &main;")); } void findGarbageCode() { // Make sure the Tokenizer::findGarbageCode() does not have FPs