From b05f19f23217ebf982f021c71a04b1df73827c35 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 19 Feb 2013 16:56:30 +0100 Subject: moc: Fix infinite recursion in macro substitution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When performing macro argument substitution, one should keep the set of macro to exclude, else we can enter an infinite recursion. Testcase: #define M1(A) A #define M2 M1(M2) Task-number: QTBUG-29759 Change-Id: I564bbfed65e1c8599592eaf12c6d67285d2fd9ce Reviewed-by: Simon Hausmann Reviewed-by: Jędrzej Nowacki --- src/tools/moc/preprocessor.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/tools/moc/preprocessor.cpp') diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp index 96b920b7cd..8f4b84a9c8 100644 --- a/src/tools/moc/preprocessor.cpp +++ b/src/tools/moc/preprocessor.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2013 Olivier Goffart ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. @@ -536,12 +537,14 @@ static Symbols tokenize(const QByteArray &input, int lineNum = 1, TokenizeMode m return symbols; } -Symbols Preprocessor::macroExpand(Preprocessor *that, Symbols &toExpand, int &index, int lineNum, bool one) +Symbols Preprocessor::macroExpand(Preprocessor *that, Symbols &toExpand, int &index, + int lineNum, bool one, const QSet &excludeSymbols) { SymbolStack symbols; SafeSymbols sf; sf.symbols = toExpand; sf.index = index; + sf.excludedSymbols = excludeSymbols; symbols.push(sf); Symbols result; @@ -664,7 +667,7 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym if (i == macro.symbols.size() - 1 || macro.symbols.at(i + 1).token != PP_HASHHASH) { Symbols arg = arguments.at(index); int idx = 1; - expansion += macroExpand(that, arg, idx, lineNum, false); + expansion += macroExpand(that, arg, idx, lineNum, false, symbols.excludeSymbols()); } else { expansion += arguments.at(index); } -- cgit v1.2.3