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); } };