Ticket 7792: Suppression both exit_code and syntaxError when call cppcheck suppressions (#1345)
This commit is contained in:
parent
d7de46f50e
commit
7ad09b44c3
|
@ -54,7 +54,7 @@ static TimerResults S_timerResults;
|
||||||
static const CWE CWE398(398U); // Indicator of Poor Code Quality
|
static const CWE CWE398(398U); // Indicator of Poor Code Quality
|
||||||
|
|
||||||
CppCheck::CppCheck(ErrorLogger &errorLogger, bool useGlobalSuppressions)
|
CppCheck::CppCheck(ErrorLogger &errorLogger, bool useGlobalSuppressions)
|
||||||
: mErrorLogger(errorLogger), mExitCode(0), mUseGlobalSuppressions(useGlobalSuppressions), mTooManyConfigs(false), mSimplify(true)
|
: mErrorLogger(errorLogger), mExitCode(0), mSuppressInternalErrorFound(false), mUseGlobalSuppressions(useGlobalSuppressions), mTooManyConfigs(false), mSimplify(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +108,7 @@ unsigned int CppCheck::check(const ImportProject::FileSettings &fs)
|
||||||
unsigned int CppCheck::checkFile(const std::string& filename, const std::string &cfgname, std::istream& fileStream)
|
unsigned int CppCheck::checkFile(const std::string& filename, const std::string &cfgname, std::istream& fileStream)
|
||||||
{
|
{
|
||||||
mExitCode = 0;
|
mExitCode = 0;
|
||||||
|
mSuppressInternalErrorFound = false;
|
||||||
|
|
||||||
// only show debug warnings for accepted C/C++ source files
|
// only show debug warnings for accepted C/C++ source files
|
||||||
if (!Path::acceptFile(filename))
|
if (!Path::acceptFile(filename))
|
||||||
|
@ -450,6 +451,10 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
|
||||||
false);
|
false);
|
||||||
|
|
||||||
reportErr(errmsg);
|
reportErr(errmsg);
|
||||||
|
if(mSuppressInternalErrorFound){
|
||||||
|
internalErrorFound = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,6 +504,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
|
||||||
if (internalErrorFound && (mExitCode==0)) {
|
if (internalErrorFound && (mExitCode==0)) {
|
||||||
mExitCode = 1;
|
mExitCode = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mExitCode;
|
return mExitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -749,6 +755,8 @@ void CppCheck::purgedConfigurationMessage(const std::string &file, const std::st
|
||||||
|
|
||||||
void CppCheck::reportErr(const ErrorLogger::ErrorMessage &msg)
|
void CppCheck::reportErr(const ErrorLogger::ErrorMessage &msg)
|
||||||
{
|
{
|
||||||
|
mSuppressInternalErrorFound = false;
|
||||||
|
|
||||||
if (!mSettings.library.reportErrors(msg.file0))
|
if (!mSettings.library.reportErrors(msg.file0))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -763,12 +771,16 @@ void CppCheck::reportErr(const ErrorLogger::ErrorMessage &msg)
|
||||||
const Suppressions::ErrorMessage errorMessage = msg.toSuppressionsErrorMessage();
|
const Suppressions::ErrorMessage errorMessage = msg.toSuppressionsErrorMessage();
|
||||||
|
|
||||||
if (mUseGlobalSuppressions) {
|
if (mUseGlobalSuppressions) {
|
||||||
if (mSettings.nomsg.isSuppressed(errorMessage))
|
if (mSettings.nomsg.isSuppressed(errorMessage)) {
|
||||||
|
mSuppressInternalErrorFound = true;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mSettings.nomsg.isSuppressedLocal(errorMessage))
|
if (mSettings.nomsg.isSuppressedLocal(errorMessage)) {
|
||||||
|
mSuppressInternalErrorFound = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!mSettings.nofail.isSuppressed(errorMessage) && (mUseGlobalSuppressions || !mSettings.nomsg.isSuppressed(errorMessage)))
|
if (!mSettings.nofail.isSuppressed(errorMessage) && (mUseGlobalSuppressions || !mSettings.nomsg.isSuppressed(errorMessage)))
|
||||||
mExitCode = 1;
|
mExitCode = 1;
|
||||||
|
|
|
@ -215,6 +215,8 @@ private:
|
||||||
|
|
||||||
unsigned int mExitCode;
|
unsigned int mExitCode;
|
||||||
|
|
||||||
|
bool mSuppressInternalErrorFound;
|
||||||
|
|
||||||
bool mUseGlobalSuppressions;
|
bool mUseGlobalSuppressions;
|
||||||
|
|
||||||
/** Are there too many configs? */
|
/** Are there too many configs? */
|
||||||
|
|
|
@ -64,6 +64,8 @@ private:
|
||||||
TEST_CASE(unusedFunction);
|
TEST_CASE(unusedFunction);
|
||||||
|
|
||||||
TEST_CASE(matchglob);
|
TEST_CASE(matchglob);
|
||||||
|
|
||||||
|
TEST_CASE(suppressingSyntaxErrorAndExitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void suppressionsBadId1() const {
|
void suppressionsBadId1() const {
|
||||||
|
@ -583,6 +585,38 @@ private:
|
||||||
ASSERT_EQUALS(true, Suppressions::matchglob("?y?", "xyz"));
|
ASSERT_EQUALS(true, Suppressions::matchglob("?y?", "xyz"));
|
||||||
ASSERT_EQUALS(true, Suppressions::matchglob("?/?/?", "x/y/z"));
|
ASSERT_EQUALS(true, Suppressions::matchglob("?/?/?", "x/y/z"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void suppressingSyntaxErrorAndExitCode() {
|
||||||
|
std::map<std::string, std::string> files;
|
||||||
|
files["test.cpp"] = "fi if;";
|
||||||
|
|
||||||
|
ASSERT_EQUALS(0, checkSuppression(files, "*:test.cpp"));
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// multi files, but only suppression one
|
||||||
|
std::map<std::string, std::string> mfiles;
|
||||||
|
mfiles["test.cpp"] = "fi if;";
|
||||||
|
mfiles["test2.cpp"] = "fi if";
|
||||||
|
ASSERT_EQUALS(1, checkSuppression(mfiles, "*:test.cpp"));
|
||||||
|
ASSERT_EQUALS("[test2.cpp:1]: (error) syntax error\n", errout.str());
|
||||||
|
|
||||||
|
// multi error in file, but only suppression one error
|
||||||
|
std::map<std::string, std::string> file2;
|
||||||
|
file2["test.cpp"] = "fi fi\n"
|
||||||
|
"if if;";
|
||||||
|
ASSERT_EQUALS(1, checkSuppression(file2, "*:test.cpp:1")); // suppress all error at line 1 of test.cpp
|
||||||
|
ASSERT_EQUALS("[test.cpp:2]: (error) syntax error\n", errout.str());
|
||||||
|
|
||||||
|
// multi error in file, but only suppression one error (2)
|
||||||
|
std::map<std::string, std::string> file3;
|
||||||
|
file3["test.cpp"] = "void f(int x, int y){\n"
|
||||||
|
" int a = x/0;\n"
|
||||||
|
" int b = y/0;\n"
|
||||||
|
"}\n"
|
||||||
|
"f(0, 1);\n";
|
||||||
|
ASSERT_EQUALS(1, checkSuppression(file3, "zerodiv:test.cpp:3")); // suppress 'errordiv' at line 3 of test.cpp
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestSuppressions)
|
REGISTER_TEST(TestSuppressions)
|
||||||
|
|
Loading…
Reference in New Issue