Fix #11639 findGarbageCode(): SIGSEGV (#4917)

This commit is contained in:
chrchr-github 2023-03-28 11:24:52 +02:00 committed by GitHub
parent 7bf6b359b1
commit 13e12da08f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -8094,7 +8094,7 @@ void Tokenizer::findGarbageCode() const
while (Token::Match(tok2, "*|&|&&")) while (Token::Match(tok2, "*|&|&&"))
tok2 = tok2->next(); tok2 = tok2->next();
if (!Token::Match(tok2, "%name%")) if (!Token::Match(tok2, "%name%"))
syntaxError(tok2, "Unexpected token '" + tok2->str() + "'"); syntaxError(tok2, "Unexpected token '" + (tok2 ? tok2->str() : "") + "'");
} }
} }
if (Token::Match(tok, "enum : %num%| {")) if (Token::Match(tok, "enum : %num%| {"))

View File

@ -253,6 +253,7 @@ private:
TEST_CASE(garbageCode220); // #6832 TEST_CASE(garbageCode220); // #6832
TEST_CASE(garbageCode221); TEST_CASE(garbageCode221);
TEST_CASE(garbageCode222); // #10763 TEST_CASE(garbageCode222); // #10763
TEST_CASE(garbageCode223); // #11639
TEST_CASE(garbageCodeFuzzerClientMode1); // test cases created with the fuzzer client, mode 1 TEST_CASE(garbageCodeFuzzerClientMode1); // test cases created with the fuzzer client, mode 1
@ -1716,6 +1717,9 @@ private:
void garbageCode222() { // #10763 void garbageCode222() { // #10763
ASSERT_THROW(checkCode("template<template<class>\n"), InternalError); // don't crash ASSERT_THROW(checkCode("template<template<class>\n"), InternalError); // don't crash
} }
void garbageCode223() { // #11639
ASSERT_THROW(checkCode("struct{}*"), InternalError); // don't crash
}
void syntaxErrorFirstToken() { void syntaxErrorFirstToken() {
ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818 ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818