Commit 6d28a58e authored by hjk's avatar hjk
Browse files

Nicer error reporting for infinite recursion



Change-Id: Idf0adfe70f46c7062ccdc0cbea309f47c5fca89e
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 71bf6cf0
...@@ -50,7 +50,9 @@ const char kFileBaseNamePostfix[] = ":FileBaseName"; ...@@ -50,7 +50,9 @@ const char kFileBaseNamePostfix[] = ":FileBaseName";
class MacroExpanderPrivate : public AbstractMacroExpander class MacroExpanderPrivate : public AbstractMacroExpander
{ {
public: public:
MacroExpanderPrivate() : m_accumulating(false), m_lockDepth(0) {} MacroExpanderPrivate()
: m_accumulating(false), m_aborted(false), m_lockDepth(0)
{}
bool resolveMacro(const QString &name, QString *ret) bool resolveMacro(const QString &name, QString *ret)
{ {
...@@ -110,6 +112,7 @@ public: ...@@ -110,6 +112,7 @@ public:
QVector<MacroExpander *> m_subExpanders; // Not owned QVector<MacroExpander *> m_subExpanders; // Not owned
bool m_accumulating; bool m_accumulating;
bool m_aborted;
int m_lockDepth; int m_lockDepth;
}; };
...@@ -264,8 +267,13 @@ QString MacroExpander::value(const QByteArray &variable, bool *found) const ...@@ -264,8 +267,13 @@ QString MacroExpander::value(const QByteArray &variable, bool *found) const
*/ */
QString MacroExpander::expand(const QString &stringWithVariables) const QString MacroExpander::expand(const QString &stringWithVariables) const
{ {
if (d->m_lockDepth > 3) // Limit recursion. if (d->m_lockDepth == 0)
d->m_aborted = false;
if (d->m_lockDepth > 3) { // Limit recursion.
d->m_aborted = true;
return QString(); return QString();
}
++d->m_lockDepth; ++d->m_lockDepth;
...@@ -274,6 +282,9 @@ QString MacroExpander::expand(const QString &stringWithVariables) const ...@@ -274,6 +282,9 @@ QString MacroExpander::expand(const QString &stringWithVariables) const
--d->m_lockDepth; --d->m_lockDepth;
if (d->m_lockDepth == 0 && d->m_aborted)
return tr("Infinite recursion error") + QLatin1String(": ") + stringWithVariables;
return res; return res;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment