CPlusPlus: Do not handle extremely long function-like macros

Qt Creator almost hangs and consumes a lot of memory if that happens.
Just ignore such cases in preprocessor.

Task-number: QTCREATORBUG-18995
Change-Id: Ib81cc18738696b02f98e5064d06c719a44ebdaa3
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Ivan Donchevskii
2018-09-13 13:15:46 +02:00
parent 5b454c95fc
commit 4b852b4e04

View File

@@ -76,6 +76,7 @@ using namespace Utils;
namespace {
enum {
MAX_FUNCTION_LIKE_ARGUMENTS_COUNT = 100,
MAX_TOKEN_EXPANSION_COUNT = 5000,
MAX_TOKEN_BUFFER_DEPTH = 16000 // for when macros are using some kind of right-folding, this is the list of "delayed" buffers waiting to be expanded after the current one.
};
@@ -1058,6 +1059,9 @@ bool Preprocessor::handleIdentifier(PPToken *tk)
argRefs);
}
if (allArgTks.size() > MAX_FUNCTION_LIKE_ARGUMENTS_COUNT)
return false;
if (!handleFunctionLikeMacro(macro, body, allArgTks, baseLine)) {
if (m_client && !idTk.expanded())
m_client->stopExpandingMacro(idTk.byteOffset, *macro);