From 999646fca626b48379b1b5eb4e1896dd20cf12f1 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Mon, 21 Feb 2011 17:49:30 -0500 Subject: [PATCH] fix #2599 (segmentation fault of cppcheck ( sizeof )) --- lib/tokenize.cpp | 3 +++ test/testsimplifytokens.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) 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() {