diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 8d0bc9b56..0e5a427ee 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -267,8 +267,13 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) _settings->_errorsOnly = true; // Append userdefined code to checked source code - else if (strncmp(argv[i], "--append=", 9) == 0) - _settings->append(9 + argv[i]); + else if (strncmp(argv[i], "--append=", 9) == 0) { + const std::string filename = 9 + argv[i]; + if (!_settings->append(filename)) { + PrintMessage("cppcheck: Couldn't open the file: \"" + filename + "\"."); + return false; + } + } else if (strncmp(argv[i], "--enable=", 9) == 0) { const std::string errmsg = _settings->addEnabled(argv[i] + 9); diff --git a/lib/settings.cpp b/lib/settings.cpp index a0029e358..2b30f4176 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -118,14 +118,18 @@ bool Settings::isEnabled(const std::string &str) const } -void Settings::append(const std::string &filename) +bool Settings::append(const std::string &filename) { _append = "\n"; std::ifstream fin(filename.c_str()); + if (!fin.is_open()) { + return false; + } std::string line; while (std::getline(fin, line)) { _append += line + "\n"; } + return true; } std::string Settings::append() const diff --git a/lib/settings.h b/lib/settings.h index f98553f5c..2d55bee8e 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -116,7 +116,7 @@ public: std::list _includePaths; /** @brief assign append code (--append) */ - void append(const std::string &filename); + bool append(const std::string &filename); /** @brief get append code (--append) */ std::string append() const;