From 69a0062177adcbed31dfa1b063f58a910670f3e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 8 Sep 2012 20:59:25 +0200 Subject: [PATCH] Tokenizer: don't crash for 'int'. Ralated with tickets #2978 and #3304 --- lib/tokenize.cpp | 2 ++ test/testsimplifytokens.cpp | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c8ced82e9..c3f2f5a29 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3343,6 +3343,8 @@ bool Tokenizer::simplifyTokenList() } tok = tok->next(); } + if (!tok) + break; } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index a9b4ef858..237f3e292 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -426,7 +426,8 @@ private: TEST_CASE(consecutiveBraces); TEST_CASE(undefinedSizeArray); - TEST_CASE(simplifyCase3304); + + TEST_CASE(simplifyArrayAddress); // Replace "&str[num]" => "(str + num)" } std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) { @@ -7918,7 +7919,7 @@ private: ASSERT_EQUALS("void f ( int x [ ] , double y [ ] ) { }", tok("void f(int x[], double y[]) { }")); } - void simplifyCase3304() { // ticket #3304 + void simplifyArrayAddress() { // ticket #3304 const char code[] = "void foo() {\n" " int a[10];\n" " memset(&a[4], 0, 20*sizeof(int));\n" @@ -7927,6 +7928,9 @@ private: " int a [ 10 ] ;" " memset ( a + 4 , 0 , 80 ) ;" " }", tok(code, true)); + + // Don't crash + tok("int", true); } };