Skip to content

Commit e789c06

Browse files
committed
Merge branch 'generic'
2 parents ee36017 + c973c26 commit e789c06

5 files changed

Lines changed: 211 additions & 1069 deletions

File tree

cli/cppcheckexecutor.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,24 @@ namespace {
102102
continue;
103103
if (ruleIds.insert(finding.id).second)
104104
{
105+
// setting name and description to empty strings will make github default
106+
// to the instance specific violation message and not rule description,
107+
// this makes it so not all the violations have the same description.
105108
picojson::object rule;
106109
rule["id"] = picojson::value(finding.id);
107110
// rule.name
108-
rule["name"] = picojson::value(finding.genericMessage());
111+
rule["name"] = picojson::value("");
109112
// rule.shortDescription.text
110113
picojson::object shortDescription;
111-
shortDescription["text"] = picojson::value(finding.genericMessage());
114+
shortDescription["text"] = picojson::value("");
112115
rule["shortDescription"] = picojson::value(shortDescription);
113116
// rule.fullDescription.text
114117
picojson::object fullDescription;
115-
fullDescription["text"] = picojson::value(finding.genericMessage());
118+
fullDescription["text"] = picojson::value("");
116119
rule["fullDescription"] = picojson::value(fullDescription);
117120
// rule.help.text
118121
picojson::object help;
119-
help["text"] = picojson::value(finding.genericMessage());
122+
help["text"] = picojson::value("");
120123
rule["help"] = picojson::value(help);
121124
// rule.properties.precision, rule.properties.problem.severity
122125
picojson::object properties;

lib/errorlogger.cpp

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,6 @@ ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg)
191191
attr = errmsg->Attribute("verbose");
192192
mVerboseMessage = attr ? attr : "";
193193

194-
attr = errmsg->Attribute("generic");
195-
mGenericMessage = attr ? attr : "";
196-
197194
attr = errmsg->Attribute("hash");
198195
hash = attr ? strToInt<std::size_t>(attr) : 0;
199196

@@ -217,75 +214,6 @@ ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg)
217214
}
218215

219216
// Convert instance-specific messages to generic ones
220-
static std::string makeGeneric(const std::string &message)
221-
{
222-
std::string result = message;
223-
224-
// Handle format string patterns first (before general single-quoted replacement)
225-
result = std::regex_replace(result, std::regex(R"(%[a-zA-Z0-9]+)"), "format specifier");
226-
227-
// Handle specific casting patterns
228-
result = std::regex_replace(
229-
result,
230-
std::regex(
231-
R"(Casting between (?:(?:const\s+|unsigned\s+|signed\s+)*[a-zA-Z_][a-zA-Z0-9_]*\s*\*+\s*and\s*(?:const\s+|unsigned\s+|signed\s+)*[a-zA-Z_][a-zA-Z0-9_]*\s*\*+) which have)"),
232-
"Casting between incompatible pointer types which have");
233-
234-
// Handle specific pointer type patterns (after casting patterns)
235-
result = std::regex_replace(
236-
result, std::regex(R"(\b(?:const\s+|unsigned\s+|signed\s+)*[a-zA-Z_][a-zA-Z0-9_]*\s*\*+)"), "pointer type");
237-
238-
// Handle specific patterns that need special treatment
239-
// Iterator condition patterns
240-
result = std::regex_replace(
241-
result,
242-
std::regex(
243-
R"(Either the condition '[^']*' is redundant or there is possible dereference of an invalid iterator[^.]*\.)"),
244-
"Either the condition is redundant or there is possible dereference of an invalid iterator.");
245-
246-
// Access moved variable patterns
247-
result = std::regex_replace(result, std::regex(R"(Access of moved variable '[^']*')"), "Access of moved variable");
248-
249-
// Variable/function/parameter patterns (before general replacement)
250-
result = std::regex_replace(result, std::regex(R"(Variable '[^']*')"), "Variable");
251-
result = std::regex_replace(result, std::regex(R"(variable '[^']*')"), "variable");
252-
result = std::regex_replace(result, std::regex(R"(Function '[^']*')"), "Function");
253-
result = std::regex_replace(result, std::regex(R"(function '[^']*')"), "function");
254-
result = std::regex_replace(result, std::regex(R"(Parameter '[^']*')"), "Parameter");
255-
result = std::regex_replace(result, std::regex(R"(parameter '[^']*')"), "parameter");
256-
result = std::regex_replace(result, std::regex(R"(Member variable '[^']*')"), "Member variable");
257-
result = std::regex_replace(result, std::regex(R"(member variable '[^']*')"), "member variable");
258-
259-
// Replace double-quoted strings with generic placeholder
260-
result = std::regex_replace(result, std::regex(R"("(?:[^"\\]|\\.)*")"), "\"string\"");
261-
262-
// Replace all remaining single-quoted identifiers with generic placeholder
263-
result = std::regex_replace(result, std::regex(R"('[^']*')"), "'identifier'");
264-
265-
// Replace all numbers with generic placeholder
266-
result = std::regex_replace(result, std::regex(R"(\b\d+\b)"), "N");
267-
268-
// Replace array access patterns
269-
result = std::regex_replace(result, std::regex(R"(\[[^\]]+\])"), "[index]");
270-
271-
// Clean up patterns that may have resulted in redundant text
272-
result = std::regex_replace(result, std::regex(R"(Variable 'identifier')"), "Variable");
273-
result = std::regex_replace(result, std::regex(R"(Function 'identifier')"), "Function");
274-
result = std::regex_replace(result, std::regex(R"(Parameter 'identifier')"), "Parameter");
275-
result = std::regex_replace(result, std::regex(R"(Member variable 'identifier')"), "Member variable");
276-
277-
// Clean up trailing colons that don't reference anything
278-
result = std::regex_replace(result, std::regex(R"(:\s*$)"), "");
279-
280-
// Clean up multiple spaces
281-
result = std::regex_replace(result, std::regex(R"(\s+)"), " ");
282-
283-
// Trim whitespace
284-
result = std::regex_replace(result, std::regex(R"(^\s+|\s+$)"), "");
285-
286-
return result;
287-
}
288-
289217
void ErrorMessage::setmsg(const std::string &msg)
290218
{
291219
// If a message ends to a '\n' and contains only a one '\n'
@@ -303,18 +231,12 @@ void ErrorMessage::setmsg(const std::string &msg)
303231
if (pos == std::string::npos) {
304232
mShortMessage = replaceStr(msg, "$symbol", symbolName);
305233
mVerboseMessage = replaceStr(msg, "$symbol", symbolName);
306-
// Set generic message (remove symbol names and make generic)
307-
const std::string msgWithoutSymbol = replaceStr(msg, "$symbol", "");
308-
mGenericMessage = makeGeneric(msgWithoutSymbol);
309234
} else if (startsWith(msg,"$symbol:")) {
310235
mSymbolNames += msg.substr(8, pos-7);
311236
setmsg(msg.substr(pos + 1));
312237
} else {
313238
mShortMessage = replaceStr(msg.substr(0, pos), "$symbol", symbolName);
314239
mVerboseMessage = replaceStr(msg.substr(pos + 1), "$symbol", symbolName);
315-
// Set generic message (remove symbol names and make generic)
316-
const std::string msgWithoutSymbol = replaceStr(msg.substr(0, pos), "$symbol", "");
317-
mGenericMessage = makeGeneric(msgWithoutSymbol);
318240
}
319241
}
320242

@@ -365,12 +287,10 @@ std::string ErrorMessage::serialize() const
365287

366288
const std::string saneShortMessage = fixInvalidChars(mShortMessage);
367289
const std::string saneVerboseMessage = fixInvalidChars(mVerboseMessage);
368-
const std::string saneGenericMessage = fixInvalidChars(mGenericMessage);
369290

370291
serializeString(oss, saneShortMessage);
371292
serializeString(oss, saneVerboseMessage);
372293
serializeString(oss, mSymbolNames);
373-
serializeString(oss, saneGenericMessage);
374294
oss += std::to_string(callStack.size());
375295
oss += " ";
376296

@@ -398,9 +318,9 @@ void ErrorMessage::deserialize(const std::string &data)
398318
callStack.clear();
399319

400320
std::istringstream iss(data);
401-
std::array<std::string, 11> results;
321+
std::array<std::string, 10> results;
402322
std::size_t elem = 0;
403-
while (iss.good() && elem < 11) {
323+
while (iss.good() && elem < 10) {
404324
unsigned int len = 0;
405325
if (!(iss >> len))
406326
throw InternalError(nullptr, "Internal Error: Deserialization of error message failed - invalid length");
@@ -426,7 +346,7 @@ void ErrorMessage::deserialize(const std::string &data)
426346
if (!iss.good())
427347
throw InternalError(nullptr, "Internal Error: Deserialization of error message failed - premature end of data");
428348

429-
if (elem != 11)
349+
if (elem != 10)
430350
throw InternalError(nullptr, "Internal Error: Deserialization of error message failed - insufficient elements");
431351

432352
id = std::move(results[0]);
@@ -450,7 +370,6 @@ void ErrorMessage::deserialize(const std::string &data)
450370
mShortMessage = std::move(results[7]);
451371
mVerboseMessage = std::move(results[8]);
452372
mSymbolNames = std::move(results[9]);
453-
mGenericMessage = std::move(results[10]);
454373

455374
unsigned int stackSize = 0;
456375
if (!(iss >> stackSize))

lib/errorlogger.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,6 @@ class CPPCHECKLIB ErrorMessage {
200200
return mSymbolNames;
201201
}
202202

203-
/** Generic message (instance-specific variables replaced with generic terms) */
204-
const std::string &genericMessage() const {
205-
return mGenericMessage;
206-
}
207-
208-
/** set generic message */
209-
void setGenericMessage(const std::string &msg);
210-
211203
static ErrorMessage fromInternalError(const InternalError &internalError, const TokenList *tokenList, const std::string &filename, const std::string& msg = "");
212204

213205
private:
@@ -221,9 +213,6 @@ class CPPCHECKLIB ErrorMessage {
221213

222214
/** symbol names */
223215
std::string mSymbolNames;
224-
225-
/** Generic message */
226-
std::string mGenericMessage;
227216
};
228217

229218
/**

test/testerrorlogger.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,6 @@ class TestErrorLogger : public TestFixture {
506506
"17 Programming error"
507507
"17 Programming error"
508508
"0 "
509-
"17 Programming error"
510509
"0 ", msg_str);
511510

512511
ErrorMessage msg2;
@@ -549,11 +548,9 @@ class TestErrorLogger : public TestFixture {
549548
"1 0"
550549
"0 "
551550
"8 test.cpp"
552-
"1 0"
553551
"17 Programming error"
554552
"17 Programming error"
555553
"0 "
556-
"17 Programming error"
557554
"0 ";
558555
ErrorMessage msg;
559556
ASSERT_THROW_INTERNAL_EQUALS(msg.deserialize(str), INTERNAL, "Internal Error: Deserialization of error message failed - invalid CWE ID - not an integer");
@@ -564,13 +561,12 @@ class TestErrorLogger : public TestFixture {
564561
"5 error"
565562
"1 0"
566563
"7 invalid" // hash
564+
"1 0"
567565
"0 "
568566
"8 test.cpp"
569-
"1 0"
570567
"17 Programming error"
571568
"17 Programming error"
572569
"0 "
573-
"17 Programming error"
574570
"0 ";
575571
ErrorMessage msg;
576572
ASSERT_THROW_INTERNAL_EQUALS(msg.deserialize(str), INTERNAL, "Internal Error: Deserialization of error message failed - invalid hash - not an integer");
@@ -608,7 +604,6 @@ class TestErrorLogger : public TestFixture {
608604
"33 Illegal character in \"foo\\001bar\""
609605
"33 Illegal character in \"foo\\001bar\""
610606
"0 "
611-
"29 Illegal character in \"string\""
612607
"0 ", msg_str);
613608

614609
ErrorMessage msg2;
@@ -637,7 +632,6 @@ class TestErrorLogger : public TestFixture {
637632
"17 Programming error"
638633
"17 Programming error"
639634
"0 "
640-
"17 Programming error"
641635
"1 "
642636
"27 654\t33\t[]:;,()\t:/,;\tabcd:/,", msg_str);
643637

0 commit comments

Comments
 (0)