From 13e12da08fd6c6e8fdb18cfab5d701f3e26f2aa9 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 28 Mar 2023 11:24:52 +0200 Subject: [PATCH] Fix #11639 findGarbageCode(): SIGSEGV (#4917) --- lib/tokenize.cpp | 2 +- test/testgarbage.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index fddb499ac..1d5214cf7 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8094,7 +8094,7 @@ void Tokenizer::findGarbageCode() const while (Token::Match(tok2, "*|&|&&")) tok2 = tok2->next(); if (!Token::Match(tok2, "%name%")) - syntaxError(tok2, "Unexpected token '" + tok2->str() + "'"); + syntaxError(tok2, "Unexpected token '" + (tok2 ? tok2->str() : "") + "'"); } } if (Token::Match(tok, "enum : %num%| {")) diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index e5b67bbb5..60930028e 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -253,6 +253,7 @@ private: TEST_CASE(garbageCode220); // #6832 TEST_CASE(garbageCode221); TEST_CASE(garbageCode222); // #10763 + TEST_CASE(garbageCode223); // #11639 TEST_CASE(garbageCodeFuzzerClientMode1); // test cases created with the fuzzer client, mode 1 @@ -1716,6 +1717,9 @@ private: void garbageCode222() { // #10763 ASSERT_THROW(checkCode("template\n"), InternalError); // don't crash } + void garbageCode223() { // #11639 + ASSERT_THROW(checkCode("struct{}*"), InternalError); // don't crash + } void syntaxErrorFirstToken() { ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818