Skip to content

Commit c5ebf26

Browse files
kkendziadanmar
authored andcommitted
cppcheck.cpp: fix suppression of syntaxError (cppcheck-opensource#1333)
* cppcheck.cpp: fix suppression of syntaxError * test: add supression test for syntaxError while file read
1 parent bbf8762 commit c5ebf26

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

lib/cppcheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
174174
it->msg,
175175
"syntaxError",
176176
false);
177-
mErrorLogger.reportErr(errmsg);
178-
return 1;
177+
reportErr(errmsg);
178+
return mExitCode;
179179
}
180180
}
181181

test/testsuppressions.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class TestSuppressions : public TestFixture {
5858
TEST_CASE(suppressionWithRelativePaths); // #4733
5959
TEST_CASE(suppressingSyntaxErrors); // #7076
6060
TEST_CASE(suppressingSyntaxErrorsInline); // #5917
61-
61+
TEST_CASE(suppressingSyntaxErrorsWhileFileRead) // PR #1333
6262
TEST_CASE(symbol);
6363

6464
TEST_CASE(unusedFunction);
@@ -523,6 +523,25 @@ class TestSuppressions : public TestFixture {
523523
ASSERT_EQUALS("", errout.str());
524524
}
525525

526+
void suppressingSyntaxErrorsWhileFileRead() { // syntaxError while file read should be suppressable (PR #1333)
527+
std::map<std::string, std::string> files;
528+
files["test.cpp"] = "CONST (genType, KS_CONST) genService[KS_CFG_NR_OF_NVM_BLOCKS] =\n"
529+
"{\n"
530+
"[!VAR \"BC\" = \"$BC + 1\"!][!//\n"
531+
"[!IF \"(as:modconf('Ks')[1]/KsGeneral/KsType = 'KS_CFG_TYPE_KS_MASTER') and\n"
532+
" (as:modconf('Ks')[1]/KsGeneral/KsUseShe = 'true')\"!][!//\n"
533+
" {\n"
534+
" &varNB_GetErrorStatus,\n"
535+
" &varNB_WriteBlock,\n"
536+
" &varNB_ReadBlock\n"
537+
" },\n"
538+
"[!VAR \"BC\" = \"$BC + 1\"!][!//\n"
539+
"[!ENDIF!][!//\n"
540+
"};";
541+
checkSuppression(files, "syntaxError:test.cpp:4");
542+
ASSERT_EQUALS("", errout.str());
543+
}
544+
526545
void symbol() {
527546
Suppressions::Suppression s;
528547
s.errorId = "foo";

0 commit comments

Comments
 (0)