From 348b2d4832e4b0074dcdd7940ec575142743cdb1 Mon Sep 17 00:00:00 2001 From: Mathias Schmid <50880400+matzeschmid@users.noreply.github.com> Date: Mon, 11 Jan 2021 18:48:56 +0100 Subject: [PATCH] Check for mandatory "name" attribute in "podtype". (#3040) --- gui/cppchecklibrarydata.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gui/cppchecklibrarydata.cpp b/gui/cppchecklibrarydata.cpp index 54bdcd1d3..7da428e64 100644 --- a/gui/cppchecklibrarydata.cpp +++ b/gui/cppchecklibrarydata.cpp @@ -35,6 +35,14 @@ static std::string unhandledElement(const QXmlStreamReader &xmlReader) throw std::runtime_error(QObject::tr("line %1: Unhandled element %2").arg(xmlReader.lineNumber()).arg(xmlReader.name().toString()).toStdString()); } +static std::string mandatoryAttibuteMissing(const QXmlStreamReader &xmlReader, QString attributeName) +{ + throw std::runtime_error(QObject::tr("line %1: Mandatory attribute '%2' missing in '%3'") + .arg(xmlReader.lineNumber()) + .arg(attributeName) + .arg(xmlReader.name().toString()).toStdString()); +} + static CppcheckLibraryData::Container loadContainer(QXmlStreamReader &xmlReader) { CppcheckLibraryData::Container container; @@ -232,6 +240,9 @@ static CppcheckLibraryData::PodType loadPodType(const QXmlStreamReader &xmlReade { CppcheckLibraryData::PodType podtype; podtype.name = xmlReader.attributes().value("name").toString(); + if (podtype.name.isEmpty()) { + mandatoryAttibuteMissing(xmlReader, "name"); + } podtype.stdtype = xmlReader.attributes().value("stdtype").toString(); podtype.size = xmlReader.attributes().value("size").toString(); podtype.sign = xmlReader.attributes().value("sign").toString();