Fixed #8357 (crash: cmake Tests/CMakeLib/testUTF8.cxx --debug --verbose) (#1046)

This commit is contained in:
IOBYTE 2018-01-22 02:06:56 -05:00 committed by amai2012
parent 512b9f512c
commit e6d285d3ca
2 changed files with 18 additions and 0 deletions

View File

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

View File

@ -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"