Add fix to support "dealloc" element in memory or resource section of library configuration. Add missing attributes to avoid loss during library configuration save. (#2978)
This commit is contained in:
parent
3470c2effa
commit
9a51fc5ba0
|
@ -198,13 +198,29 @@ static CppcheckLibraryData::MemoryResource loadMemoryResource(QXmlStreamReader &
|
||||||
if (type != QXmlStreamReader::StartElement)
|
if (type != QXmlStreamReader::StartElement)
|
||||||
continue;
|
continue;
|
||||||
const QString elementName = xmlReader.name().toString();
|
const QString elementName = xmlReader.name().toString();
|
||||||
if (elementName == "alloc") {
|
if (elementName == "alloc" || elementName == "realloc") {
|
||||||
CppcheckLibraryData::MemoryResource::Alloc alloc;
|
CppcheckLibraryData::MemoryResource::Alloc alloc;
|
||||||
|
alloc.isRealloc = (elementName == "realloc");
|
||||||
alloc.init = (xmlReader.attributes().value("init").toString() == "true");
|
alloc.init = (xmlReader.attributes().value("init").toString() == "true");
|
||||||
|
if (xmlReader.attributes().hasAttribute("arg")) {
|
||||||
|
alloc.arg = xmlReader.attributes().value("arg").toInt();
|
||||||
|
}
|
||||||
|
if (alloc.isRealloc && xmlReader.attributes().hasAttribute("realloc-arg")) {
|
||||||
|
alloc.reallocArg = xmlReader.attributes().value("realloc-arg").toInt();
|
||||||
|
}
|
||||||
|
if (memoryresource.type == "memory") {
|
||||||
|
alloc.bufferSize = xmlReader.attributes().value("buffer-size").toString();
|
||||||
|
}
|
||||||
alloc.name = xmlReader.readElementText();
|
alloc.name = xmlReader.readElementText();
|
||||||
memoryresource.alloc.append(alloc);
|
memoryresource.alloc.append(alloc);
|
||||||
} else if (elementName == "dealloc")
|
} else if (elementName == "dealloc") {
|
||||||
memoryresource.dealloc.append(xmlReader.readElementText());
|
CppcheckLibraryData::MemoryResource::Dealloc dealloc;
|
||||||
|
if (xmlReader.attributes().hasAttribute("arg")) {
|
||||||
|
dealloc.arg = xmlReader.attributes().value("arg").toInt();
|
||||||
|
}
|
||||||
|
dealloc.name = xmlReader.readElementText();
|
||||||
|
memoryresource.dealloc.append(dealloc);
|
||||||
|
}
|
||||||
else if (elementName == "use")
|
else if (elementName == "use")
|
||||||
memoryresource.use.append(xmlReader.readElementText());
|
memoryresource.use.append(xmlReader.readElementText());
|
||||||
else
|
else
|
||||||
|
@ -437,14 +453,34 @@ static void writeMemoryResource(QXmlStreamWriter &xmlWriter, const CppcheckLibra
|
||||||
{
|
{
|
||||||
xmlWriter.writeStartElement(mr.type);
|
xmlWriter.writeStartElement(mr.type);
|
||||||
foreach (const CppcheckLibraryData::MemoryResource::Alloc &alloc, mr.alloc) {
|
foreach (const CppcheckLibraryData::MemoryResource::Alloc &alloc, mr.alloc) {
|
||||||
|
if (alloc.isRealloc) {
|
||||||
|
xmlWriter.writeStartElement("realloc");
|
||||||
|
} else {
|
||||||
xmlWriter.writeStartElement("alloc");
|
xmlWriter.writeStartElement("alloc");
|
||||||
|
}
|
||||||
xmlWriter.writeAttribute("init", alloc.init ? "true" : "false");
|
xmlWriter.writeAttribute("init", alloc.init ? "true" : "false");
|
||||||
|
if (alloc.arg != -1) {
|
||||||
|
xmlWriter.writeAttribute("arg", QString("%1").arg(alloc.arg));
|
||||||
|
}
|
||||||
|
if (alloc.isRealloc && alloc.reallocArg != -1) {
|
||||||
|
xmlWriter.writeAttribute("realloc-arg", QString("%1").arg(alloc.reallocArg));
|
||||||
|
}
|
||||||
|
if (mr.type == "memory" && !alloc.bufferSize.isEmpty()) {
|
||||||
|
xmlWriter.writeAttribute("buffer-size", alloc.bufferSize);
|
||||||
|
}
|
||||||
xmlWriter.writeCharacters(alloc.name);
|
xmlWriter.writeCharacters(alloc.name);
|
||||||
xmlWriter.writeEndElement();
|
xmlWriter.writeEndElement();
|
||||||
}
|
}
|
||||||
foreach (const QString &dealloc, mr.dealloc) {
|
|
||||||
xmlWriter.writeTextElement("dealloc", dealloc);
|
foreach (const CppcheckLibraryData::MemoryResource::Dealloc &dealloc, mr.dealloc) {
|
||||||
|
xmlWriter.writeStartElement("dealloc");
|
||||||
|
if (dealloc.arg != -1) {
|
||||||
|
xmlWriter.writeAttribute("arg", QString("%1").arg(dealloc.arg));
|
||||||
|
}
|
||||||
|
xmlWriter.writeCharacters(dealloc.name);
|
||||||
|
xmlWriter.writeEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (const QString &use, mr.use) {
|
foreach (const QString &use, mr.use) {
|
||||||
xmlWriter.writeTextElement("use", use);
|
xmlWriter.writeTextElement("use", use);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Cppcheck - A tool for static C/C++ code analysis
|
* Cppcheck - A tool for static C/C++ code analysis
|
||||||
* Copyright (C) 2007-2018 Cppcheck team.
|
* Copyright (C) 2007-2020 Cppcheck team.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -136,12 +136,31 @@ public:
|
||||||
struct MemoryResource {
|
struct MemoryResource {
|
||||||
QString type; // "memory" or "resource"
|
QString type; // "memory" or "resource"
|
||||||
struct Alloc {
|
struct Alloc {
|
||||||
Alloc() : init(false) {}
|
Alloc() :
|
||||||
|
isRealloc(false),
|
||||||
|
init(false),
|
||||||
|
arg(-1), // -1: Has no optional "arg" attribute
|
||||||
|
reallocArg(-1) // -1: Has no optional "realloc-arg" attribute
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool isRealloc;
|
||||||
bool init;
|
bool init;
|
||||||
|
int arg;
|
||||||
|
int reallocArg;
|
||||||
|
QString bufferSize;
|
||||||
QString name;
|
QString name;
|
||||||
};
|
};
|
||||||
|
struct Dealloc {
|
||||||
|
Dealloc() :
|
||||||
|
arg(-1) // -1: Has no optional "arg" attribute
|
||||||
|
{}
|
||||||
|
|
||||||
|
int arg;
|
||||||
|
QString name;
|
||||||
|
};
|
||||||
|
|
||||||
QList<struct Alloc> alloc;
|
QList<struct Alloc> alloc;
|
||||||
QStringList dealloc;
|
QList<struct Dealloc> dealloc;
|
||||||
QStringList use;
|
QStringList use;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -181,4 +200,4 @@ public:
|
||||||
QStringList undefines;
|
QStringList undefines;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LIBRARYDATA_H
|
#endif // CPPCHECKLIBRARYDATA_H
|
||||||
|
|
Loading…
Reference in New Issue