Nicer error reporting for infinite recursion

Change-Id: Idf0adfe70f46c7062ccdc0cbea309f47c5fca89e
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
hjk
2014-11-05 12:31:03 +01:00
parent 71bf6cf03e
commit 6d28a58e94

View File

@@ -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:
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
*/ */
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
--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;
} }