Fixed #5512 (library (memory): extending standard free deallocator with allocators in custom cppcheck configuration file)

This commit is contained in:
Daniel Marjamäki 2014-04-19 13:15:06 +02:00
parent ed54b93317
commit 0c5707ebf1
2 changed files with 46 additions and 6 deletions

View File

@ -92,19 +92,35 @@ bool Library::load(const tinyxml2::XMLDocument &doc)
for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
if (strcmp(node->Name(),"memory")==0 || strcmp(node->Name(),"resource")==0) {
if (strcmp(node->Name(), "memory")==0)
while (!ismemory(++allocid));
else
while (!isresource(++allocid));
// get allocationId to use..
int allocationId = 0;
for (const tinyxml2::XMLElement *memorynode = node->FirstChildElement(); memorynode; memorynode = memorynode->NextSiblingElement()) {
if (strcmp(memorynode->Name(),"dealloc")==0) {
const std::map<std::string,int>::const_iterator it = _dealloc.find(memorynode->GetText());
if (it != _dealloc.end()) {
allocationId = it->second;
break;
}
}
}
if (allocationId == 0) {
if (strcmp(node->Name(), "memory")==0)
while (!ismemory(++allocid));
else
while (!isresource(++allocid));
allocationId = allocid;
}
// add alloc/dealloc/use functions..
for (const tinyxml2::XMLElement *memorynode = node->FirstChildElement(); memorynode; memorynode = memorynode->NextSiblingElement()) {
if (strcmp(memorynode->Name(),"alloc")==0) {
_alloc[memorynode->GetText()] = allocid;
_alloc[memorynode->GetText()] = allocationId;
const char *init = memorynode->Attribute("init");
if (init && strcmp(init,"false")==0) {
returnuninitdata.insert(memorynode->GetText());
}
} else if (strcmp(memorynode->Name(),"dealloc")==0)
_dealloc[memorynode->GetText()] = allocid;
_dealloc[memorynode->GetText()] = allocationId;
else if (strcmp(memorynode->Name(),"use")==0)
use.insert(memorynode->GetText());
else

View File

@ -34,6 +34,7 @@ private:
TEST_CASE(function_arg);
TEST_CASE(function_arg_any);
TEST_CASE(memory);
TEST_CASE(memory2); // define extra "free" allocation functions
TEST_CASE(resource);
}
@ -127,6 +128,29 @@ private:
ASSERT(Library::ismemory(library.alloc("CreateX")));
ASSERT_EQUALS(library.alloc("CreateX"), library.dealloc("DeleteX"));
}
void memory2() const {
const char xmldata1[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <memory>\n"
" <alloc>malloc</alloc>\n"
" <dealloc>free</dealloc>\n"
" </memory>\n"
"</def>";
const char xmldata2[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <memory>\n"
" <alloc>foo</alloc>\n"
" <dealloc>free</dealloc>\n"
" </memory>\n"
"</def>";
Library library;
library.loadxmldata(xmldata1, sizeof(xmldata1));
library.loadxmldata(xmldata2, sizeof(xmldata2));
ASSERT_EQUALS(library.dealloc("free"), library.alloc("malloc"));
ASSERT_EQUALS(library.dealloc("free"), library.alloc("foo"));
}
void resource() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"