Skip to content

Commit cad4e4a

Browse files
b4ndanmar
authored andcommitted
Fix handling of sizeof &var (danmar#1498)
Fixes https://trac.cppcheck.net/ticket/8870
1 parent 86f9840 commit cad4e4a

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3340,7 +3340,7 @@ void Tokenizer::sizeofAddParentheses()
33403340
for (Token *tok = list.front(); tok; tok = tok->next()) {
33413341
if (!Token::Match(tok, "sizeof !!("))
33423342
continue;
3343-
if (tok->next()->isLiteral() || Token::Match(tok->next(), "%name%|*|~|!")) {
3343+
if (tok->next()->isLiteral() || Token::Match(tok->next(), "%name%|*|~|!|&")) {
33443344
Token *endToken = tok->next();
33453345
while (Token::simpleMatch(endToken, "* *"))
33463346
endToken = endToken->next();

test/testtokenize.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8662,6 +8662,7 @@ class TestTokenizer : public TestFixture {
86628662
ASSERT_EQUALS("sizeof ( a . b ) + 3 ;", tokenizeAndStringify("sizeof a.b+3;"));
86638663
ASSERT_EQUALS("sizeof ( a [ 2 ] . b ) + 3 ;", tokenizeAndStringify("sizeof a[2].b+3;"));
86648664
ASSERT_EQUALS("f ( 0 , sizeof ( ptr . bar ) ) ;", tokenizeAndStringify("f(0, sizeof ptr->bar );"));
8665+
ASSERT_EQUALS("sizeof ( a ) > sizeof ( & main ) ;", tokenizeAndStringify("sizeof a > sizeof &main;"));
86658666
}
86668667

86678668
void findGarbageCode() { // Make sure the Tokenizer::findGarbageCode() does not have FPs

0 commit comments

Comments
 (0)