Skip to content

Commit 2d29764

Browse files
committed
fix #13961
1 parent 8e62a24 commit 2d29764

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

cli/processexecutor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ namespace {
116116
suppr_str += suppr.checked ? "1" : "0";
117117
suppr_str += ";";
118118
suppr_str += suppr.matched ? "1" : "0";
119+
suppr_str += ";";
120+
suppr_str += suppr.extraComment;
119121
return suppr_str;
120122
}
121123

@@ -239,7 +241,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
239241
if (!buf.empty()) {
240242
// TODO: avoid string splitting
241243
auto parts = splitString(buf, ';');
242-
if (parts.size() != 3)
244+
if (parts.size() != 4)
243245
{
244246
// TODO: make this non-fatal
245247
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") adding of inline suppression failed - insufficient data" << std::endl;
@@ -249,6 +251,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
249251
suppr.isInline = (type == PipeWriter::REPORT_SUPPR_INLINE);
250252
suppr.checked = parts[1] == "1";
251253
suppr.matched = parts[2] == "1";
254+
suppr.extraComment = parts[3];
252255
const std::string err = mSuppressions.nomsg.addSuppression(suppr);
253256
if (!err.empty()) {
254257
// TODO: only update state if it doesn't exist - otherwise propagate error

lib/suppressions.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,22 @@ bool SuppressionList::Suppression::parseComment(std::string comment, std::string
334334
if (comment.size() < 2)
335335
return false;
336336

337-
if (comment.find(';') != std::string::npos)
338-
comment.erase(comment.find(';'));
339-
340-
if (comment.find("//", 2) != std::string::npos)
341-
comment.erase(comment.find("//",2));
342-
343337
if (comment.compare(comment.size() - 2, 2, "*/") == 0)
344338
comment.erase(comment.size() - 2, 2);
345339

340+
std::string::size_type extraPos = comment.find(';');
341+
std::string::size_type extraDelimiterSize = 1;
342+
343+
if (extraPos == std::string::npos) {
344+
extraPos = comment.find("//", 2);
345+
extraDelimiterSize = 2;
346+
}
347+
348+
if (extraPos != std::string::npos) {
349+
extraComment = trim(comment.substr(extraPos + extraDelimiterSize));
350+
comment.erase(extraPos);
351+
}
352+
346353
const std::set<std::string> cppchecksuppress{
347354
"cppcheck-suppress",
348355
"cppcheck-suppress-begin",
@@ -532,6 +539,12 @@ void SuppressionList::dump(std::ostream & out) const
532539
out << " type=\"blockEnd\"";
533540
else if (suppression.type == SuppressionList::Type::macro)
534541
out << " type=\"macro\"";
542+
if (suppression.isInline)
543+
out << " inline=\"true\"";
544+
else
545+
out << " inline=\"false\"";
546+
if (!suppression.extraComment.empty())
547+
out << " comment=\"" << suppression.extraComment << "\"";
535548
out << " />" << std::endl;
536549
}
537550
out << " </suppressions>" << std::endl;

lib/suppressions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class CPPCHECKLIB SuppressionList {
151151

152152
std::string errorId;
153153
std::string fileName;
154+
std::string extraComment;
154155
int lineNumber = NO_LINE;
155156
int lineBegin = NO_LINE;
156157
int lineEnd = NO_LINE;

0 commit comments

Comments
 (0)