Skip to content

Commit b3943c0

Browse files
committed
fix
1 parent 4e62f0c commit b3943c0

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

cli/cppcheckexecutor.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,13 @@ void StdLogger::reportErr(const ErrorMessage &msg)
661661
msgCopy.classification = getClassification(msgCopy.guideline, mSettings.reportType);
662662

663663
// TODO: there should be no need for verbose and default messages here
664+
// Don't perform redundant reads for these formats, the code is not needed
665+
// for deduplication
666+
const bool noCode = mSettings.outputFormat == Settings::OutputFormat::xml ||
667+
mSettings.outputFormat == Settings::OutputFormat::sarif;
664668
const std::string msgStr =
665-
msgCopy.toString(mSettings.verbose, mSettings.templateFormat, mSettings.templateLocation);
669+
msgCopy.toString(mSettings.verbose, mSettings.templateFormat,
670+
mSettings.templateLocation, noCode);
666671

667672
// Alert only about unique errors
668673
if (!mSettings.emitDuplicates && !mShownErrors.insert(msgStr).second)

lib/cppcheck.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ class CppCheck::CppCheckLogger : public ErrorLogger
210210
}
211211

212212
// TODO: there should be no need for the verbose and default messages here
213-
std::string errmsg = msg.toString(mSettings.verbose, mSettings.templateFormat, mSettings.templateLocation);
213+
// Code is not needed for deduplication
214+
const bool noCode = true;
215+
std::string errmsg = msg.toString(mSettings.verbose, mSettings.templateFormat, mSettings.templateLocation, noCode);
214216
if (errmsg.empty())
215217
return;
216218

lib/errorlogger.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ static void replaceColors(std::string& source, bool erase) {
696696
replace(source, substitutionMapErase);
697697
}
698698

699-
std::string ErrorMessage::toString(bool verbose, const std::string &templateFormat, const std::string &templateLocation) const
699+
std::string ErrorMessage::toString(bool verbose, const std::string &templateFormat, const std::string &templateLocation, bool noCode) const
700700
{
701701
assert(!templateFormat.empty());
702702

@@ -737,7 +737,8 @@ std::string ErrorMessage::toString(bool verbose, const std::string &templateForm
737737
endl = "\r\n";
738738
else
739739
endl = "\r";
740-
findAndReplace(result, "{code}", readCode(callStack.back().getOrigFile(), callStack.back().line, callStack.back().column, endl));
740+
const std::string code = noCode ? "" : readCode(callStack.back().getOrigFile(), callStack.back().line, callStack.back().column, endl);
741+
findAndReplace(result, "{code}", code);
741742
}
742743
} else {
743744
static const std::unordered_map<std::string, std::string> callStackSubstitutionMap =
@@ -768,7 +769,8 @@ std::string ErrorMessage::toString(bool verbose, const std::string &templateForm
768769
endl = "\r\n";
769770
else
770771
endl = "\r";
771-
findAndReplace(text, "{code}", readCode(fileLocation.getOrigFile(), fileLocation.line, fileLocation.column, endl));
772+
const std::string code = noCode ? "" : readCode(callStack.back().getOrigFile(), callStack.back().line, callStack.back().column, endl);
773+
findAndReplace(text, "{code}", code);
772774
}
773775
result += '\n' + text;
774776
}

lib/errorlogger.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,13 @@ class CPPCHECKLIB ErrorMessage {
152152
* or template to be used. E.g. "{file}:{line},{severity},{id},{message}"
153153
* @param templateLocation Format Empty string to use default output format
154154
* or template to be used. E.g. "{file}:{line},{info}"
155+
* @param noCode Always replace {code} with an empty string
155156
* @return formatted string
156157
*/
157158
std::string toString(bool verbose,
158159
const std::string &templateFormat,
159-
const std::string &templateLocation) const;
160+
const std::string &templateLocation,
161+
bool noCode = false) const;
160162

161163
std::string serialize() const;
162164
/**

0 commit comments

Comments
 (0)