Rename 'cppcheckID' to 'hash'

This commit is contained in:
Daniel Marjamäki 2020-07-21 11:27:03 +02:00
parent ae0ad17152
commit 4ab04db53c
14 changed files with 80 additions and 80 deletions

View File

@ -25,7 +25,7 @@
</attribute> </attribute>
</optional> </optional>
<optional> <optional>
<attribute name="cppcheck-id"> <attribute name="hash">
<data type="integer"> <data type="integer">
<param name="minExclusive">1</param> <param name="minExclusive">1</param>
</data> </data>

View File

@ -37,7 +37,7 @@ ErrorItem::ErrorItem()
, incomplete(false) , incomplete(false)
, inconclusive(false) , inconclusive(false)
, cwe(-1) , cwe(-1)
, cppcheckId(0) , hash(0)
{ {
} }
@ -51,7 +51,7 @@ ErrorItem::ErrorItem(const ErrorMessage &errmsg)
, summary(QString::fromStdString(errmsg.shortMessage())) , summary(QString::fromStdString(errmsg.shortMessage()))
, message(QString::fromStdString(errmsg.verboseMessage())) , message(QString::fromStdString(errmsg.verboseMessage()))
, cwe(errmsg.cwe.id) , cwe(errmsg.cwe.id)
, cppcheckId(errmsg.cppcheckId) , hash(errmsg.hash)
, symbolNames(QString::fromStdString(errmsg.symbolNames())) , symbolNames(QString::fromStdString(errmsg.symbolNames()))
{ {
for (std::list<ErrorMessage::FileLocation>::const_iterator loc = errmsg.callStack.begin(); for (std::list<ErrorMessage::FileLocation>::const_iterator loc = errmsg.callStack.begin();
@ -88,8 +88,8 @@ QString ErrorItem::toString() const
bool ErrorItem::sameCID(const ErrorItem &errorItem1, const ErrorItem &errorItem2) bool ErrorItem::sameCID(const ErrorItem &errorItem1, const ErrorItem &errorItem2)
{ {
if (errorItem1.cppcheckId || errorItem2.cppcheckId) if (errorItem1.hash || errorItem2.hash)
return errorItem1.cppcheckId == errorItem2.cppcheckId; return errorItem1.hash == errorItem2.hash;
// fallback // fallback
return errorItem1.errorId == errorItem2.errorId && return errorItem1.errorId == errorItem2.errorId &&

View File

@ -88,7 +88,7 @@ public:
QString summary; QString summary;
QString message; QString message;
int cwe; int cwe;
unsigned long long cppcheckId; unsigned long long hash;
QList<QErrorPathItem> errorPath; QList<QErrorPathItem> errorPath;
QString symbolNames; QString symbolNames;
@ -115,7 +115,7 @@ public:
QString errorId; QString errorId;
bool incomplete; bool incomplete;
int cwe; int cwe;
unsigned long long cppcheckId; unsigned long long hash;
bool inconclusive; bool inconclusive;
Severity::SeverityType severity; Severity::SeverityType severity;
QString summary; QString summary;

View File

@ -610,8 +610,8 @@ void ProjectFile::readSuppressions(QXmlStreamReader &reader)
suppression.lineNumber = reader.attributes().value(QString(),"lineNumber").toInt(); suppression.lineNumber = reader.attributes().value(QString(),"lineNumber").toInt();
if (reader.attributes().hasAttribute(QString(),"symbolName")) if (reader.attributes().hasAttribute(QString(),"symbolName"))
suppression.symbolName = reader.attributes().value(QString(),"symbolName").toString().toStdString(); suppression.symbolName = reader.attributes().value(QString(),"symbolName").toString().toStdString();
if (reader.attributes().hasAttribute(QString(),"cppcheck-id")) if (reader.attributes().hasAttribute(QString(),"hash"))
suppression.cppcheckId = reader.attributes().value(QString(),"cppcheck-id").toULongLong(); suppression.hash = reader.attributes().value(QString(),"hash").toULongLong();
type = reader.readNext(); type = reader.readNext();
if (type == QXmlStreamReader::Characters) { if (type == QXmlStreamReader::Characters) {
suppression.errorId = reader.text().toString().toStdString(); suppression.errorId = reader.text().toString().toStdString();
@ -650,8 +650,8 @@ void ProjectFile::readTagWarnings(QXmlStreamReader &reader, const QString &tag)
case QXmlStreamReader::StartElement: case QXmlStreamReader::StartElement:
// Read library-elements // Read library-elements
if (reader.name().toString() == CppcheckXml::WarningElementName) { if (reader.name().toString() == CppcheckXml::WarningElementName) {
std::size_t cppcheckId = reader.attributes().value(QString(), CppcheckXml::CppcheckIdAttributeName).toULongLong(); std::size_t hash = reader.attributes().value(QString(), CppcheckXml::HashAttributeName).toULongLong();
mWarningTags[cppcheckId] = tag; mWarningTags[hash] = tag;
} }
break; break;
@ -774,17 +774,17 @@ void ProjectFile::setVSConfigurations(const QStringList &vsConfigs)
mVsConfigurations = vsConfigs; mVsConfigurations = vsConfigs;
} }
void ProjectFile::setWarningTags(std::size_t cppcheckId, QString tag) void ProjectFile::setWarningTags(std::size_t hash, QString tag)
{ {
if (tag.isEmpty()) if (tag.isEmpty())
mWarningTags.erase(cppcheckId); mWarningTags.erase(hash);
else if (cppcheckId > 0) else if (hash > 0)
mWarningTags[cppcheckId] = tag; mWarningTags[hash] = tag;
} }
QString ProjectFile::getWarningTags(std::size_t cppcheckId) const QString ProjectFile::getWarningTags(std::size_t hash) const
{ {
auto it = mWarningTags.find(cppcheckId); auto it = mWarningTags.find(hash);
return (it != mWarningTags.end()) ? it->second : QString(); return (it != mWarningTags.end()) ? it->second : QString();
} }
@ -936,8 +936,8 @@ bool ProjectFile::write(const QString &filename)
xmlWriter.writeAttribute("lineNumber", QString::number(suppression.lineNumber)); xmlWriter.writeAttribute("lineNumber", QString::number(suppression.lineNumber));
if (!suppression.symbolName.empty()) if (!suppression.symbolName.empty())
xmlWriter.writeAttribute("symbolName", QString::fromStdString(suppression.symbolName)); xmlWriter.writeAttribute("symbolName", QString::fromStdString(suppression.symbolName));
if (suppression.cppcheckId > 0) if (suppression.hash > 0)
xmlWriter.writeAttribute(CppcheckXml::CppcheckIdAttributeName, QString::number(suppression.cppcheckId)); xmlWriter.writeAttribute(CppcheckXml::HashAttributeName, QString::number(suppression.hash));
if (!suppression.errorId.empty()) if (!suppression.errorId.empty())
xmlWriter.writeCharacters(QString::fromStdString(suppression.errorId)); xmlWriter.writeCharacters(QString::fromStdString(suppression.errorId));
xmlWriter.writeEndElement(); xmlWriter.writeEndElement();
@ -981,7 +981,7 @@ bool ProjectFile::write(const QString &filename)
for (const auto wt: mWarningTags) { for (const auto wt: mWarningTags) {
if (wt.second == tag) { if (wt.second == tag) {
xmlWriter.writeStartElement(CppcheckXml::WarningElementName); xmlWriter.writeStartElement(CppcheckXml::WarningElementName);
xmlWriter.writeAttribute(CppcheckXml::CppcheckIdAttributeName, QString::number(wt.first)); xmlWriter.writeAttribute(CppcheckXml::HashAttributeName, QString::number(wt.first));
xmlWriter.writeEndElement(); xmlWriter.writeEndElement();
} }
} }

View File

@ -332,10 +332,10 @@ public:
} }
/** Set tags for a warning */ /** Set tags for a warning */
void setWarningTags(std::size_t cppcheckId, QString tags); void setWarningTags(std::size_t hash, QString tags);
/** Get tags for a warning */ /** Get tags for a warning */
QString getWarningTags(std::size_t cppcheckId) const; QString getWarningTags(std::size_t hash) const;
/** /**
* @brief Write project file (to disk). * @brief Write project file (to disk).

View File

@ -50,12 +50,12 @@
#include "xmlreportv2.h" #include "xmlreportv2.h"
static const char COLUMN[] = "column"; static const char COLUMN[] = "column";
static const char CPPCHECKID[] = "cppcheckId";
static const char CWE[] = "cwe"; static const char CWE[] = "cwe";
static const char ERRORID[] = "id"; static const char ERRORID[] = "id";
static const char FILENAME[] = "file"; static const char FILENAME[] = "file";
static const char FILE0[] = "file0"; static const char FILE0[] = "file0";
static const char FUNCTION[] = "function"; static const char FUNCTION[] = "function";
static const char HASH[] = "hash";
static const char HIDE[] = "hide"; static const char HIDE[] = "hide";
static const char INCOMPLETE[] = "incomplete"; static const char INCOMPLETE[] = "incomplete";
static const char INCONCLUSIVE[] = "inconclusive"; static const char INCONCLUSIVE[] = "inconclusive";
@ -187,14 +187,14 @@ bool ResultsTree::addErrorItem(const ErrorItem &item)
line.errorId = item.errorId; line.errorId = item.errorId;
line.incomplete = item.incomplete; line.incomplete = item.incomplete;
line.cwe = item.cwe; line.cwe = item.cwe;
line.cppcheckId = item.cppcheckId; line.hash = item.hash;
line.inconclusive = item.inconclusive; line.inconclusive = item.inconclusive;
line.summary = item.summary; line.summary = item.summary;
line.message = item.message; line.message = item.message;
line.severity = item.severity; line.severity = item.severity;
line.sinceDate = item.sinceDate; line.sinceDate = item.sinceDate;
if (const ProjectFile *activeProject = ProjectFile::getActiveProject()) { if (const ProjectFile *activeProject = ProjectFile::getActiveProject()) {
line.tags = activeProject->getWarningTags(item.cppcheckId); line.tags = activeProject->getWarningTags(item.hash);
} }
//Create the base item for the error and ensure it has a proper //Create the base item for the error and ensure it has a proper
//file item as a parent //file item as a parent
@ -219,7 +219,7 @@ bool ResultsTree::addErrorItem(const ErrorItem &item)
data[ERRORID] = item.errorId; data[ERRORID] = item.errorId;
data[INCOMPLETE] = item.incomplete; data[INCOMPLETE] = item.incomplete;
data[CWE] = item.cwe; data[CWE] = item.cwe;
data[CPPCHECKID] = item.cppcheckId; data[HASH] = item.hash;
data[INCONCLUSIVE] = item.inconclusive; data[INCONCLUSIVE] = item.inconclusive;
data[FILE0] = stripPath(item.file0, true); data[FILE0] = stripPath(item.file0, true);
data[FUNCTION] = item.function; data[FUNCTION] = item.function;
@ -256,7 +256,7 @@ bool ResultsTree::addErrorItem(const ErrorItem &item)
child_data[ERRORID] = line.errorId; child_data[ERRORID] = line.errorId;
child_data[INCOMPLETE] = line.incomplete; child_data[INCOMPLETE] = line.incomplete;
child_data[CWE] = line.cwe; child_data[CWE] = line.cwe;
child_data[CPPCHECKID] = line.cppcheckId; child_data[HASH] = line.hash;
child_data[INCONCLUSIVE] = line.inconclusive; child_data[INCONCLUSIVE] = line.inconclusive;
child_data[SYMBOLNAMES] = item.symbolNames; child_data[SYMBOLNAMES] = item.symbolNames;
child_item->setData(QVariant(child_data)); child_item->setData(QVariant(child_data));
@ -661,7 +661,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
QAction *copy = new QAction(tr("Copy"), &menu); QAction *copy = new QAction(tr("Copy"), &menu);
QAction *hide = new QAction(tr("Hide"), &menu); QAction *hide = new QAction(tr("Hide"), &menu);
QAction *hideallid = new QAction(tr("Hide all with id"), &menu); QAction *hideallid = new QAction(tr("Hide all with id"), &menu);
QAction *suppressCppcheckID = new QAction(tr("Suppress cppcheck-id"), &menu); QAction *suppresshash = new QAction(tr("Suppress hash"), &menu);
QAction *opencontainingfolder = new QAction(tr("Open containing folder"), &menu); QAction *opencontainingfolder = new QAction(tr("Open containing folder"), &menu);
if (multipleSelection) { if (multipleSelection) {
@ -679,7 +679,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
menu.addSeparator(); menu.addSeparator();
menu.addAction(hide); menu.addAction(hide);
menu.addAction(hideallid); menu.addAction(hideallid);
menu.addAction(suppressCppcheckID); menu.addAction(suppresshash);
if (!bughunting) { if (!bughunting) {
QAction *suppress = new QAction(tr("Suppress selected id(s)"), &menu); QAction *suppress = new QAction(tr("Suppress selected id(s)"), &menu);
menu.addAction(suppress); menu.addAction(suppress);
@ -692,7 +692,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
connect(copy, SIGNAL(triggered()), this, SLOT(copy())); connect(copy, SIGNAL(triggered()), this, SLOT(copy()));
connect(hide, SIGNAL(triggered()), this, SLOT(hideResult())); connect(hide, SIGNAL(triggered()), this, SLOT(hideResult()));
connect(hideallid, SIGNAL(triggered()), this, SLOT(hideAllIdResult())); connect(hideallid, SIGNAL(triggered()), this, SLOT(hideAllIdResult()));
connect(suppressCppcheckID, &QAction::triggered, this, &ResultsTree::suppressCppcheckID); connect(suppresshash, &QAction::triggered, this, &ResultsTree::suppressHash);
connect(opencontainingfolder, SIGNAL(triggered()), this, SLOT(openContainingFolder())); connect(opencontainingfolder, SIGNAL(triggered()), this, SLOT(openContainingFolder()));
const ProjectFile *currentProject = ProjectFile::getActiveProject(); const ProjectFile *currentProject = ProjectFile::getActiveProject();
@ -1066,7 +1066,7 @@ void ResultsTree::suppressSelectedIds()
emit suppressIds(selectedIds.toList()); emit suppressIds(selectedIds.toList());
} }
void ResultsTree::suppressCppcheckID() void ResultsTree::suppressHash()
{ {
if (!mSelectionModel) if (!mSelectionModel)
return; return;
@ -1087,9 +1087,9 @@ void ResultsTree::suppressCppcheckID()
for (QStandardItem *item: selectedWarnings) { for (QStandardItem *item: selectedWarnings) {
QStandardItem *fileItem = item->parent(); QStandardItem *fileItem = item->parent();
const QVariantMap data = item->data().toMap(); const QVariantMap data = item->data().toMap();
if (projectFile && data.contains("cppcheckId")) { if (projectFile && data.contains(HASH)) {
Suppressions::Suppression suppression; Suppressions::Suppression suppression;
suppression.cppcheckId = data[CPPCHECKID].toULongLong(); suppression.hash = data[HASH].toULongLong();
suppression.errorId = data[ERRORID].toString().toStdString(); suppression.errorId = data[ERRORID].toString().toStdString();
suppression.fileName = data[FILENAME].toString().toStdString(); suppression.fileName = data[FILENAME].toString().toStdString();
suppression.lineNumber = data[LINE].toInt(); suppression.lineNumber = data[LINE].toInt();
@ -1132,9 +1132,9 @@ void ResultsTree::tagSelectedItems(const QString &tag)
data[TAGS] = tag; data[TAGS] = tag;
item->setData(QVariant(data)); item->setData(QVariant(data));
item->parent()->child(index.row(), COLUMN_TAGS)->setText(tag); item->parent()->child(index.row(), COLUMN_TAGS)->setText(tag);
if (currentProject && data.contains(CPPCHECKID)) { if (currentProject && data.contains(HASH)) {
isTagged = true; isTagged = true;
currentProject->setWarningTags(data[CPPCHECKID].toULongLong(), tag); currentProject->setWarningTags(data[HASH].toULongLong(), tag);
} }
} }
} }
@ -1296,7 +1296,7 @@ void ResultsTree::readErrorItem(const QStandardItem *error, ErrorItem *item) con
item->errorId = data[ERRORID].toString(); item->errorId = data[ERRORID].toString();
item->incomplete = data[INCOMPLETE].toBool(); item->incomplete = data[INCOMPLETE].toBool();
item->cwe = data[CWE].toInt(); item->cwe = data[CWE].toInt();
item->cppcheckId = data[CPPCHECKID].toULongLong(); item->hash = data[HASH].toULongLong();
item->inconclusive = data[INCONCLUSIVE].toBool(); item->inconclusive = data[INCONCLUSIVE].toBool();
item->file0 = data[FILE0].toString(); item->file0 = data[FILE0].toString();
item->sinceDate = data[SINCEDATE].toString(); item->sinceDate = data[SINCEDATE].toString();

View File

@ -276,8 +276,8 @@ protected slots:
/** Slot for context menu item to suppress all messages with the current message id */ /** Slot for context menu item to suppress all messages with the current message id */
void suppressSelectedIds(); void suppressSelectedIds();
/** Slot for context menu item to suppress message with cppcheck ID */ /** Slot for context menu item to suppress message with hash */
void suppressCppcheckID(); void suppressHash();
/** /**
* @brief Slot for context menu item to open the folder containing the current file. * @brief Slot for context menu item to open the folder containing the current file.

View File

@ -34,7 +34,7 @@ static const QString ErrorElementName = "error";
static const QString ErrorsElementName = "errors"; static const QString ErrorsElementName = "errors";
static const QString LocationElementName = "location"; static const QString LocationElementName = "location";
static const QString CWEAttribute = "cwe"; static const QString CWEAttribute = "cwe";
static const QString CppcheckIdAttribute = "cppcheck-id"; static const QString HashAttribute = "hash";
static const QString SinceDateAttribute = "sinceDate"; static const QString SinceDateAttribute = "sinceDate";
static const QString TagsAttribute = "tag"; static const QString TagsAttribute = "tag";
static const QString FilenameAttribute = "file"; static const QString FilenameAttribute = "file";
@ -123,8 +123,8 @@ void XmlReportV2::writeError(const ErrorItem &error)
mXmlWriter->writeAttribute(InconclusiveAttribute, "true"); mXmlWriter->writeAttribute(InconclusiveAttribute, "true");
if (error.cwe > 0) if (error.cwe > 0)
mXmlWriter->writeAttribute(CWEAttribute, QString::number(error.cwe)); mXmlWriter->writeAttribute(CWEAttribute, QString::number(error.cwe));
if (error.cppcheckId > 0) if (error.hash > 0)
mXmlWriter->writeAttribute(CppcheckIdAttribute, QString::number(error.cppcheckId)); mXmlWriter->writeAttribute(HashAttribute, QString::number(error.hash));
if (!error.sinceDate.isEmpty()) if (!error.sinceDate.isEmpty())
mXmlWriter->writeAttribute(SinceDateAttribute, error.sinceDate); mXmlWriter->writeAttribute(SinceDateAttribute, error.sinceDate);
if (!error.tags.isEmpty()) if (!error.tags.isEmpty())
@ -218,8 +218,8 @@ ErrorItem XmlReportV2::readError(QXmlStreamReader *reader)
item.inconclusive = true; item.inconclusive = true;
if (attribs.hasAttribute(QString(), CWEAttribute)) if (attribs.hasAttribute(QString(), CWEAttribute))
item.cwe = attribs.value(QString(), CWEAttribute).toInt(); item.cwe = attribs.value(QString(), CWEAttribute).toInt();
if (attribs.hasAttribute(QString(), CppcheckIdAttribute)) if (attribs.hasAttribute(QString(), HashAttribute))
item.cppcheckId = attribs.value(QString(), CppcheckIdAttribute).toULongLong(); item.hash = attribs.value(QString(), HashAttribute).toULongLong();
if (attribs.hasAttribute(QString(), SinceDateAttribute)) if (attribs.hasAttribute(QString(), SinceDateAttribute))
item.sinceDate = attribs.value(QString(), SinceDateAttribute).toString(); item.sinceDate = attribs.value(QString(), SinceDateAttribute).toString();
if (attribs.hasAttribute(QString(), TagsAttribute)) if (attribs.hasAttribute(QString(), TagsAttribute))

View File

@ -59,7 +59,7 @@ InternalError::InternalError(const Token *tok, const std::string &errorMsg, Type
} }
} }
static std::size_t calculateCppcheckId(const TokenList *tokenList, const std::string &msg) static std::size_t calculateWarningHash(const TokenList *tokenList, const std::string &msg)
{ {
if (!tokenList) if (!tokenList)
return 0; return 0;
@ -67,7 +67,7 @@ static std::size_t calculateCppcheckId(const TokenList *tokenList, const std::st
} }
ErrorMessage::ErrorMessage() ErrorMessage::ErrorMessage()
: incomplete(false), severity(Severity::none), cwe(0U), inconclusive(false), cppcheckId(0) : incomplete(false), severity(Severity::none), cwe(0U), inconclusive(false), hash(0)
{ {
} }
@ -79,7 +79,7 @@ ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack, const std::
severity(severity), // severity for this error message severity(severity), // severity for this error message
cwe(0U), cwe(0U),
inconclusive(inconclusive), inconclusive(inconclusive),
cppcheckId(0) hash(0)
{ {
// set the summary and verbose messages // set the summary and verbose messages
setmsg(msg); setmsg(msg);
@ -95,14 +95,14 @@ ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack, const std::
severity(severity), // severity for this error message severity(severity), // severity for this error message
cwe(cwe.id), cwe(cwe.id),
inconclusive(inconclusive), inconclusive(inconclusive),
cppcheckId(0) hash(0)
{ {
// set the summary and verbose messages // set the summary and verbose messages
setmsg(msg); setmsg(msg);
} }
ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive) ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive)
: id(id), incomplete(false), severity(severity), cwe(0U), inconclusive(inconclusive), cppcheckId(0) : id(id), incomplete(false), severity(severity), cwe(0U), inconclusive(inconclusive), hash(0)
{ {
// Format callstack // Format callstack
for (std::list<const Token *>::const_iterator it = callstack.begin(); it != callstack.end(); ++it) { for (std::list<const Token *>::const_iterator it = callstack.begin(); it != callstack.end(); ++it) {
@ -137,7 +137,7 @@ ErrorMessage::ErrorMessage(const std::list<const Token*>& callstack, const Token
setmsg(msg); setmsg(msg);
cppcheckId = calculateCppcheckId(list, toString(false)); hash = calculateWarningHash(list, toString(false));
} }
ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenList, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, bool inconclusive) ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenList, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, bool inconclusive)
@ -158,7 +158,7 @@ ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenLis
setmsg(msg); setmsg(msg);
cppcheckId = calculateCppcheckId(tokenList, toString(false)); hash = calculateWarningHash(tokenList, toString(false));
} }
ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg) ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg)
@ -187,8 +187,8 @@ ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg)
attr = errmsg->Attribute("verbose"); attr = errmsg->Attribute("verbose");
mVerboseMessage = attr ? attr : ""; mVerboseMessage = attr ? attr : "";
attr = errmsg->Attribute("cppcheck-id"); attr = errmsg->Attribute("hash");
std::istringstream(attr ? attr : "0") >> cppcheckId; std::istringstream(attr ? attr : "0") >> hash;
for (const tinyxml2::XMLElement *e = errmsg->FirstChildElement(); e; e = e->NextSiblingElement()) { for (const tinyxml2::XMLElement *e = errmsg->FirstChildElement(); e; e = e->NextSiblingElement()) {
if (std::strcmp(e->Name(),"location")==0) { if (std::strcmp(e->Name(),"location")==0) {
@ -235,7 +235,7 @@ void ErrorMessage::setmsg(const std::string &msg)
Suppressions::ErrorMessage ErrorMessage::toSuppressionsErrorMessage() const Suppressions::ErrorMessage ErrorMessage::toSuppressionsErrorMessage() const
{ {
Suppressions::ErrorMessage ret; Suppressions::ErrorMessage ret;
ret.cppcheckId = cppcheckId; ret.hash = hash;
ret.errorId = id; ret.errorId = id;
if (!callStack.empty()) { if (!callStack.empty()) {
ret.setFileName(callStack.back().getfile(false)); ret.setFileName(callStack.back().getfile(false));
@ -254,7 +254,7 @@ std::string ErrorMessage::serialize() const
oss << id.length() << " " << id; oss << id.length() << " " << id;
oss << Severity::toString(severity).length() << " " << Severity::toString(severity); oss << Severity::toString(severity).length() << " " << Severity::toString(severity);
oss << MathLib::toString(cwe.id).length() << " " << MathLib::toString(cwe.id); oss << MathLib::toString(cwe.id).length() << " " << MathLib::toString(cwe.id);
oss << MathLib::toString(cppcheckId).length() << " " << MathLib::toString(cppcheckId); oss << MathLib::toString(hash).length() << " " << MathLib::toString(hash);
if (inconclusive) { if (inconclusive) {
const std::string text("inconclusive"); const std::string text("inconclusive");
oss << text.length() << " " << text; oss << text.length() << " " << text;
@ -309,7 +309,7 @@ bool ErrorMessage::deserialize(const std::string &data)
id = results[0]; id = results[0];
severity = Severity::fromString(results[1]); severity = Severity::fromString(results[1]);
std::istringstream(results[2]) >> cwe.id; std::istringstream(results[2]) >> cwe.id;
std::istringstream(results[3]) >> cppcheckId; std::istringstream(results[3]) >> hash;
mShortMessage = results[4]; mShortMessage = results[4];
mVerboseMessage = results[5]; mVerboseMessage = results[5];
@ -418,8 +418,8 @@ std::string ErrorMessage::toXML() const
printer.PushAttribute("verbose", fixInvalidChars(mVerboseMessage).c_str()); printer.PushAttribute("verbose", fixInvalidChars(mVerboseMessage).c_str());
if (cwe.id) if (cwe.id)
printer.PushAttribute("cwe", cwe.id); printer.PushAttribute("cwe", cwe.id);
if (cppcheckId) if (hash)
printer.PushAttribute("cppcheck-id", MathLib::toString(cppcheckId).c_str()); printer.PushAttribute("hash", MathLib::toString(hash).c_str());
if (inconclusive) if (inconclusive)
printer.PushAttribute("inconclusive", "true"); printer.PushAttribute("inconclusive", "true");

View File

@ -196,8 +196,8 @@ public:
CWE cwe; CWE cwe;
bool inconclusive; bool inconclusive;
/** Warning ID */ /** Warning hash */
std::size_t cppcheckId; std::size_t hash;
/** set short and verbose messages */ /** set short and verbose messages */
void setmsg(const std::string &msg); void setmsg(const std::string &msg);

View File

@ -1086,7 +1086,7 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
s.fileName = joinRelativePath(path, s.fileName); s.fileName = joinRelativePath(path, s.fileName);
s.lineNumber = child->IntAttribute("lineNumber", Suppressions::Suppression::NO_LINE); s.lineNumber = child->IntAttribute("lineNumber", Suppressions::Suppression::NO_LINE);
s.symbolName = read(child->Attribute("symbolName"), ""); s.symbolName = read(child->Attribute("symbolName"), "");
std::istringstream(read(child->Attribute("cppcheck-id"), "0")) >> s.cppcheckId; std::istringstream(read(child->Attribute("hash"), "0")) >> s.hash;
suppressions.push_back(s); suppressions.push_back(s);
} }
} else if (strcmp(node->Name(), CppcheckXml::VSConfigurationElementName) == 0) } else if (strcmp(node->Name(), CppcheckXml::VSConfigurationElementName) == 0)

View File

@ -164,7 +164,7 @@ namespace CppcheckXml {
const char TagWarningsElementName[] = "tag-warnings"; const char TagWarningsElementName[] = "tag-warnings";
const char TagAttributeName[] = "tag"; const char TagAttributeName[] = "tag";
const char WarningElementName[] = "warning"; const char WarningElementName[] = "warning";
const char CppcheckIdAttributeName[] = "cppcheck-id"; const char HashAttributeName[] = "hash";
const char CheckHeadersElementName[] = "check-headers"; const char CheckHeadersElementName[] = "check-headers";
const char CheckUnusedTemplatesElementName[] = "check-unused-templates"; const char CheckUnusedTemplatesElementName[] = "check-unused-templates";
const char MaxCtuDepthElementName[] = "max-ctu-depth"; const char MaxCtuDepthElementName[] = "max-ctu-depth";

View File

@ -85,7 +85,7 @@ std::string Suppressions::parseXmlFile(const char *filename)
const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement(); const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement();
for (const tinyxml2::XMLElement * e = rootnode->FirstChildElement(); e; e = e->NextSiblingElement()) { for (const tinyxml2::XMLElement * e = rootnode->FirstChildElement(); e; e = e->NextSiblingElement()) {
if (std::strcmp(e->Name(), "suppress") != 0) if (std::strcmp(e->Name(), "suppress") != 0)
return "Invalid suppression xml file format, expected <suppress> element but got a <" + std::string(e->Name()) + '>'; return "Invalid suppression xml file format, expected <suppress> element but got a \"" + std::string(e->Name()) + '\"';
Suppression s; Suppression s;
for (const tinyxml2::XMLElement * e2 = e->FirstChildElement(); e2; e2 = e2->NextSiblingElement()) { for (const tinyxml2::XMLElement * e2 = e->FirstChildElement(); e2; e2 = e2->NextSiblingElement()) {
@ -98,10 +98,10 @@ std::string Suppressions::parseXmlFile(const char *filename)
s.lineNumber = std::atoi(text); s.lineNumber = std::atoi(text);
else if (std::strcmp(e2->Name(), "symbolName") == 0) else if (std::strcmp(e2->Name(), "symbolName") == 0)
s.symbolName = text; s.symbolName = text;
else if (*text && std::strcmp(e2->Name(), "cppcheckId") == 0) else if (*text && std::strcmp(e2->Name(), "hash") == 0)
std::istringstream(text) >> s.cppcheckId; std::istringstream(text) >> s.hash;
else else
return "Unknown suppression element <" + std::string(e2->Name()) + ">, expected <id>/<fileName>/<lineNumber>/<symbolName>/<cppcheckId>"; return "Unknown suppression element \"" + std::string(e2->Name()) + "\", expected id/fileName/lineNumber/symbolName/hash";
} }
const std::string err = addSuppression(s); const std::string err = addSuppression(s);
@ -206,7 +206,7 @@ std::string Suppressions::addSuppressionLine(const std::string &line)
std::string Suppressions::addSuppression(const Suppressions::Suppression &suppression) std::string Suppressions::addSuppression(const Suppressions::Suppression &suppression)
{ {
// Check that errorId is valid.. // Check that errorId is valid..
if (suppression.errorId.empty() && suppression.cppcheckId == 0) if (suppression.errorId.empty() && suppression.hash == 0)
return "Failed to add suppression. No id."; return "Failed to add suppression. No id.";
if (suppression.errorId != "*") { if (suppression.errorId != "*") {
@ -273,7 +273,7 @@ bool Suppressions::Suppression::parseComment(std::string comment, std::string *e
bool Suppressions::Suppression::isSuppressed(const Suppressions::ErrorMessage &errmsg) const bool Suppressions::Suppression::isSuppressed(const Suppressions::ErrorMessage &errmsg) const
{ {
if (cppcheckId > 0 && cppcheckId != errmsg.cppcheckId) if (hash > 0 && hash != errmsg.hash)
return false; return false;
if (!errorId.empty() && !matchglob(errorId, errmsg.errorId)) if (!errorId.empty() && !matchglob(errorId, errmsg.errorId))
return false; return false;
@ -319,8 +319,8 @@ std::string Suppressions::Suppression::getText() const
ret += " lineNumber=" + MathLib::toString(lineNumber); ret += " lineNumber=" + MathLib::toString(lineNumber);
if (!symbolName.empty()) if (!symbolName.empty())
ret += " symbolName=" + symbolName; ret += " symbolName=" + symbolName;
if (cppcheckId > 0) if (hash > 0)
ret += " cppcheckId=" + MathLib::toString(cppcheckId); ret += " hash=" + MathLib::toString(hash);
if (ret.compare(0,1," ")==0) if (ret.compare(0,1," ")==0)
return ret.substr(1); return ret.substr(1);
return ret; return ret;
@ -364,8 +364,8 @@ void Suppressions::dump(std::ostream & out) const
out << " lineNumber=\"" << suppression.lineNumber << '"'; out << " lineNumber=\"" << suppression.lineNumber << '"';
if (!suppression.symbolName.empty()) if (!suppression.symbolName.empty())
out << " symbolName=\"" << ErrorLogger::toxml(suppression.symbolName) << '\"'; out << " symbolName=\"" << ErrorLogger::toxml(suppression.symbolName) << '\"';
if (suppression.cppcheckId > 0) if (suppression.hash > 0)
out << " cppcheckId=\"" << suppression.cppcheckId << '\"'; out << " hash=\"" << suppression.hash << '\"';
out << " />" << std::endl; out << " />" << std::endl;
} }
out << " </suppressions>" << std::endl; out << " </suppressions>" << std::endl;
@ -377,7 +377,7 @@ std::list<Suppressions::Suppression> Suppressions::getUnmatchedLocalSuppressions
for (const Suppression &s : mSuppressions) { for (const Suppression &s : mSuppressions) {
if (s.matched) if (s.matched)
continue; continue;
if (s.cppcheckId > 0) if (s.hash > 0)
continue; continue;
if (!unusedFunctionChecking && s.errorId == "unusedFunction") if (!unusedFunctionChecking && s.errorId == "unusedFunction")
continue; continue;
@ -394,7 +394,7 @@ std::list<Suppressions::Suppression> Suppressions::getUnmatchedGlobalSuppression
for (const Suppression &s : mSuppressions) { for (const Suppression &s : mSuppressions) {
if (s.matched) if (s.matched)
continue; continue;
if (s.cppcheckId > 0) if (s.hash > 0)
continue; continue;
if (!unusedFunctionChecking && s.errorId == "unusedFunction") if (!unusedFunctionChecking && s.errorId == "unusedFunction")
continue; continue;

View File

@ -35,7 +35,7 @@ class CPPCHECKLIB Suppressions {
public: public:
struct CPPCHECKLIB ErrorMessage { struct CPPCHECKLIB ErrorMessage {
std::size_t cppcheckId; std::size_t hash;
std::string errorId; std::string errorId;
void setFileName(const std::string &s); void setFileName(const std::string &s);
const std::string &getFileName() const { const std::string &getFileName() const {
@ -49,18 +49,18 @@ public:
}; };
struct CPPCHECKLIB Suppression { struct CPPCHECKLIB Suppression {
Suppression() : lineNumber(NO_LINE), cppcheckId(0), matched(false) {} Suppression() : lineNumber(NO_LINE), hash(0), matched(false) {}
Suppression(const Suppression &other) { Suppression(const Suppression &other) {
*this = other; *this = other;
} }
Suppression(const std::string &id, const std::string &file, int line=NO_LINE) : errorId(id), fileName(file), lineNumber(line), cppcheckId(0), matched(false) {} Suppression(const std::string &id, const std::string &file, int line=NO_LINE) : errorId(id), fileName(file), lineNumber(line), hash(0), matched(false) {}
Suppression & operator=(const Suppression &other) { Suppression & operator=(const Suppression &other) {
errorId = other.errorId; errorId = other.errorId;
fileName = other.fileName; fileName = other.fileName;
lineNumber = other.lineNumber; lineNumber = other.lineNumber;
symbolName = other.symbolName; symbolName = other.symbolName;
cppcheckId = other.cppcheckId; hash = other.hash;
matched = other.matched; matched = other.matched;
return *this; return *this;
} }
@ -74,8 +74,8 @@ public:
return fileName < other.fileName; return fileName < other.fileName;
if (symbolName != other.symbolName) if (symbolName != other.symbolName)
return symbolName < other.symbolName; return symbolName < other.symbolName;
if (cppcheckId != other.cppcheckId) if (hash != other.hash)
return cppcheckId < other.cppcheckId; return hash < other.hash;
return false; return false;
} }
@ -100,7 +100,7 @@ public:
std::string fileName; std::string fileName;
int lineNumber; int lineNumber;
std::string symbolName; std::string symbolName;
std::size_t cppcheckId; std::size_t hash;
bool matched; bool matched;
enum { NO_LINE = -1 }; enum { NO_LINE = -1 };