diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 1dffa395d..b5eb2c29a 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -156,19 +156,9 @@ void CppCheck::parseFromArgs(int argc, const char* const argv[]) } - else if (strcmp(argv[i], "--enable") == 0) - _settings.addEnabled(""); - else if (strncmp(argv[i], "--enable=", 9) == 0) { - std::string s(9 + argv[i]); - if (s[0] == '\"') - s.erase(0, 1); - std::string::size_type pos = s.find("\""); - if (pos != std::string::npos) - s.erase(pos, 1); - - _settings.addEnabled(s); + _settings.addEnabled(argv[i] + 9); } // --error-exitcode=1 diff --git a/lib/settings.cpp b/lib/settings.cpp index 4bc29c809..4b4e615ca 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -21,6 +21,7 @@ #include #include #include +#include Settings::Settings() { @@ -115,40 +116,37 @@ bool Settings::isSuppressed(const std::string &errorId, const std::string &file, void Settings::addEnabled(const std::string &str) { - if (str.length() == 0) + if (str == "all") + _checkCodingStyle = _showAll = _force = true; + else if (str == "style") + _checkCodingStyle = true; + else if (str == "possibleError") + _showAll = true; + + std::set id; + id.insert("exceptNew"); + id.insert("exceptRealloc"); + id.insert("unusedFunctions"); + + if (str == "all") { - _enabled["*"] = true; + std::set::const_iterator it; + for (it = id.begin(); it != id.end(); ++it) + _enabled[*it] = true; + } + else if (id.find(str) != id.end()) + { + _enabled[str] = true; } else { - std::string::size_type prevPos = 0; - std::string::size_type pos = 0; - while ((pos = str.find_first_of(",", pos)) != std::string::npos) - { - if (prevPos != pos) - _enabled[str.substr(prevPos, pos-prevPos)] = true; - - ++pos; - prevPos = pos; - } - - if (prevPos < str.length()) - _enabled[str.substr(prevPos, pos-prevPos)] = true; + throw std::runtime_error("wrong --enable argument '" + str + "'"); } - - if (isEnabled("style")) - _checkCodingStyle = true; - if (isEnabled("possibleError")) - _showAll = true; } bool Settings::isEnabled(const std::string &str) const { - if (_enabled.find("*") != _enabled.end() || - _enabled.find(str) != _enabled.end()) - return true; - else - return false; + return bool(_enabled.find(str) != _enabled.end()); } void Settings::addAutoAllocClass(const std::string &name) diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index 6e41fe764..15465067d 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -53,7 +53,7 @@ private: // Check char variable usage.. Settings settings; - settings.addEnabled(""); + settings.addEnabled("all"); CheckExceptionSafety checkExceptionSafety(&tokenizer, &settings, this); checkExceptionSafety.runSimplifiedChecks(&tokenizer, &settings, this); }