Skip to content

Commit 348b2d4

Browse files
authored
Check for mandatory "name" attribute in "podtype". (cppcheck-opensource#3040)
1 parent b1c56d3 commit 348b2d4

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

gui/cppchecklibrarydata.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ static std::string unhandledElement(const QXmlStreamReader &xmlReader)
3535
throw std::runtime_error(QObject::tr("line %1: Unhandled element %2").arg(xmlReader.lineNumber()).arg(xmlReader.name().toString()).toStdString());
3636
}
3737

38+
static std::string mandatoryAttibuteMissing(const QXmlStreamReader &xmlReader, QString attributeName)
39+
{
40+
throw std::runtime_error(QObject::tr("line %1: Mandatory attribute '%2' missing in '%3'")
41+
.arg(xmlReader.lineNumber())
42+
.arg(attributeName)
43+
.arg(xmlReader.name().toString()).toStdString());
44+
}
45+
3846
static CppcheckLibraryData::Container loadContainer(QXmlStreamReader &xmlReader)
3947
{
4048
CppcheckLibraryData::Container container;
@@ -232,6 +240,9 @@ static CppcheckLibraryData::PodType loadPodType(const QXmlStreamReader &xmlReade
232240
{
233241
CppcheckLibraryData::PodType podtype;
234242
podtype.name = xmlReader.attributes().value("name").toString();
243+
if (podtype.name.isEmpty()) {
244+
mandatoryAttibuteMissing(xmlReader, "name");
245+
}
235246
podtype.stdtype = xmlReader.attributes().value("stdtype").toString();
236247
podtype.size = xmlReader.attributes().value("size").toString();
237248
podtype.sign = xmlReader.attributes().value("sign").toString();

0 commit comments

Comments
 (0)