diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 085734ef677..db00e18a8d6 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -168,6 +168,8 @@ static bool parseInlineSuppressionCommentToken(const simplecpp::Token *tok, std: } static std::string getRelativeFilename(const simplecpp::Token* tok, const Settings &settings) { + if (!tok) + return ""; std::string relativeFilename(tok->location.file()); if (settings.relativePaths) { for (const std::string & basePath : settings.basePaths) { @@ -1079,6 +1081,8 @@ void Preprocessor::addRemarkComments(const simplecpp::TokenList &tokens, std::ve remarkedToken = prev; break; } + if (!remarkedToken) + continue; // Relative filename const std::string relativeFilename = getRelativeFilename(remarkedToken, mSettings); diff --git a/test/cli/fuzz-crash/crash-2cf8ffd04628a7c025bb07074462a51c1284dff0 b/test/cli/fuzz-crash/crash-2cf8ffd04628a7c025bb07074462a51c1284dff0 new file mode 100644 index 00000000000..ffa34fb944d --- /dev/null +++ b/test/cli/fuzz-crash/crash-2cf8ffd04628a7c025bb07074462a51c1284dff0 @@ -0,0 +1 @@ +//REMARK / \ No newline at end of file diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index e73d6373f6c..fe893858dba 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -195,6 +195,7 @@ class TestPreprocessor : public TestFixture { TEST_CASE(remarkComment1); TEST_CASE(remarkComment2); TEST_CASE(remarkComment3); + TEST_CASE(remarkComment4); // Using -D to predefine symbols TEST_CASE(predefine1); @@ -1940,6 +1941,12 @@ class TestPreprocessor : public TestFixture { ASSERT_EQUALS("assignment with 1 ", remarkComments[0].str); } + void remarkComment4() { + const char code[] = "//REMARK /"; + const auto remarkComments = PreprocessorHelper::getRemarkComments(code, *this); + ASSERT_EQUALS(0, remarkComments.size()); + } + void predefine1() { const std::string src("#if defined X || Y\n" "Fred & Wilma\n"