aboutsummaryrefslogtreecommitdiffstats
path: root/typesystem.cpp
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-02-17 10:15:45 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-09 19:10:15 -0300
commitd63acce85c01257af96809f1081ab479d1f703a8 (patch)
treee78a9e9f566dff5aac4795c325745d4996b3f269 /typesystem.cpp
parent2ca6e422c0a4c58fad74fe523abb25716df81ce2 (diff)
Added a depth counter to avoid segmentation faults when discarding type entries.
And an unit test was added. Reviewed by Lauro Moura <lauro.neto@openbossa.org> Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'typesystem.cpp')
-rw-r--r--typesystem.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/typesystem.cpp b/typesystem.cpp
index 3ccb33543..c9f6ac734 100644
--- a/typesystem.cpp
+++ b/typesystem.cpp
@@ -38,7 +38,8 @@ Handler::Handler(TypeDatabase* database, bool generate)
{
m_currentEnum = 0;
m_current = 0;
- m_currentOptional = 0;
+ m_currentDroppedEntry = 0;
+ m_currentDroppedEntryDepth = 0;
tagNames["rejection"] = StackElement::Rejection;
tagNames["primitive-type"] = StackElement::PrimitiveTypeEntry;
@@ -124,10 +125,15 @@ void Handler::fetchAttributeValues(const QString &name, const QXmlAttributes &at
bool Handler::endElement(const QString &, const QString &localName, const QString &)
{
- if (m_currentOptional) {
- m_current = m_currentOptional->parent;
- delete m_currentOptional;
- m_currentOptional = 0;
+ if (m_currentDroppedEntry) {
+ if (m_currentDroppedEntryDepth == 1) {
+ m_current = m_currentDroppedEntry->parent;
+ delete m_currentDroppedEntry;
+ m_currentDroppedEntry = 0;
+ m_currentDroppedEntryDepth = 0;
+ } else {
+ ++m_currentDroppedEntryDepth;
+ }
return true;
}
@@ -216,7 +222,7 @@ bool Handler::endElement(const QString &, const QString &localName, const QStrin
bool Handler::characters(const QString &ch)
{
- if (m_currentOptional)
+ if (m_currentDroppedEntry)
return true;
if (m_current->type == StackElement::Template) {
@@ -383,8 +389,10 @@ bool Handler::startElement(const QString &, const QString &n,
return false;
}
- if (m_currentOptional)
+ if (m_currentDroppedEntry) {
+ ++m_currentDroppedEntryDepth;
return true;
+ }
StackElement* element = new StackElement(m_current);
element->type = tagNames[tagName];
@@ -461,8 +469,9 @@ bool Handler::startElement(const QString &, const QString &n,
QString identifier = getNamePrefix(element) + '.';
identifier += (element->type == StackElement::FunctionTypeEntry ? attributes["signature"] : name);
if (m_database->shouldDropTypeEntry(identifier)) {
- m_currentOptional = element;
- ReportHandler::debugSparse(QString("Optional type system entry '%1' was dropped from generation.").arg(identifier));
+ m_currentDroppedEntry = element;
+ m_currentDroppedEntryDepth = 1;
+ ReportHandler::debugSparse(QString("Type system entry '%1' was intentionally dropped from generation.").arg(identifier));
return true;
}
}