From 6c28bd82ec312a9c74acb7a365360f7d60cc6948 Mon Sep 17 00:00:00 2001 From: foryoung365 Date: Mon, 21 Oct 2024 18:34:39 +0800 Subject: [PATCH] Fix the null pointer exception issue in Tokenizer::dump Fix the problem where when there is a header file with the same name in the current source code path and the include path, it is incorrectly matched to the header file in the include path --- externals/simplecpp/simplecpp.cpp | 32 ++++++++++++++++++++++++++----- lib/tokenize.cpp | 2 +- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/externals/simplecpp/simplecpp.cpp b/externals/simplecpp/simplecpp.cpp index d2fa6ee3082..2bef0d39671 100755 --- a/externals/simplecpp/simplecpp.cpp +++ b/externals/simplecpp/simplecpp.cpp @@ -3134,6 +3134,21 @@ static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const return openHeaderIncludePath(f, dui, header); return ret; } +static bool IsFileExists(const std::string& simplePath) +{ + if (simplePath.empty()) + { + return false; + } + + std::ifstream ifs(simplePath); + if (ifs.good()) + { + return true; + } + + return false; +} static std::string getFileName(const std::map &filedata, const std::string &sourcefile, const std::string &header, const simplecpp::DUI &dui, bool systemheader) { @@ -3144,11 +3159,18 @@ static std::string getFileName(const std::map::const_iterator it = dui.includePaths.begin(); it != dui.includePaths.end(); ++it) { std::string s = simplecpp::simplifyPath(getIncludePathFileName(*it, header)); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 36a6b00c34f..12e5590147f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6158,7 +6158,7 @@ void Tokenizer::dump(std::ostream &out) const } containers.insert(tok->valueType()->container); } - if (!tok->varId() && tok->scope()->isExecutable() && Token::Match(tok, "%name% (")) { + if (!tok->varId() && tok->scope() && tok->scope()->isExecutable() && Token::Match(tok, "%name% (")) { if (mSettings.library.isnoreturn(tok)) outs += " noreturn=\"true\""; }