diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index cb23f4c39..c52059dd5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3809,6 +3809,9 @@ void Tokenizer::simplifySizeof() if (tok->str() != "sizeof") continue; + if (!tok->next()) + break; + if (Token::simpleMatch(tok->next(), "sizeof")) continue; diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 58273fa4a..e883f6adb 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -84,6 +84,7 @@ private: TEST_CASE(sizeof19); // #1891 - sizeof 'x' TEST_CASE(sizeof20); // #2024 - sizeof a) TEST_CASE(sizeof21); // #2232 - sizeof...(Args) + TEST_CASE(sizeof22); // #2599 TEST_CASE(sizeofsizeof); TEST_CASE(casting); @@ -1418,6 +1419,15 @@ private: tok(code); } + void sizeof22() + { + // ticket #2599 segmentation fault + const char code[] = "sizeof\n"; + + // don't segfault + tok(code); + } + void sizeofsizeof() {