From e6d285d3cac1774437905a1b32d1990b108a6ca3 Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Mon, 22 Jan 2018 02:06:56 -0500 Subject: [PATCH] Fixed #8357 (crash: cmake Tests/CMakeLib/testUTF8.cxx --debug --verbose) (#1046) --- lib/tokenize.cpp | 7 +++++++ test/testsimplifytypedef.cpp | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index cce6a484a..4dd796d9b 100755 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1500,6 +1500,9 @@ void Tokenizer::simplifyTypedef() if (!inCast && !inSizeof) tok2 = tok2->next(); + if (tok2->str() == "const") + tok2 = tok2->next(); + // reference to array? if (tok2->str() == "&") { tok2 = tok2->previous(); @@ -1522,6 +1525,10 @@ void Tokenizer::simplifyTypedef() if (!tok2->next()) syntaxError(tok2); // can't recover so quit + // skip over array dimensions + while (tok2->next()->str() == "[") + tok2 = tok2->linkAt(1); + tok2 = TokenList::copyTokens(tok2, arrayStart, arrayEnd); if (!tok2->next()) syntaxError(tok2); diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index ca464f770..89d944cfe 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -157,6 +157,7 @@ private: TEST_CASE(simplifyTypedef117); // ticket #6507 TEST_CASE(simplifyTypedef118); // ticket #5749 TEST_CASE(simplifyTypedef119); // ticket #7541 + TEST_CASE(simplifyTypedef120); // ticket #8357 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -2443,6 +2444,16 @@ private: ASSERT_EQUALS("", errout.str()); } + void simplifyTypedef120() { // #8357 + const char code[] = "typedef char test_utf8_char[5];\n" + "static test_utf8_char const bad_chars[] = { };\n" + "static void report_good(bool passed, test_utf8_char const c) { };"; + const char exp [] = "static const char bad_chars [ ] [ 5 ] = { } ; " + "static void report_good ( bool passed , const char c [ 5 ] ) { } ;"; + ASSERT_EQUALS(exp, tok(code, false)); + ASSERT_EQUALS("", errout.str()); + } + void simplifyTypedefFunction1() { { const char code[] = "typedef void (*my_func)();\n"