diff --git a/Units/parser-asm.r/asm-cpp-macro-expansion-with-limitation.d/args.ctags b/Units/parser-asm.r/asm-cpp-macro-expansion-with-limitation.d/args.ctags new file mode 100644 index 0000000000..9970460147 --- /dev/null +++ b/Units/parser-asm.r/asm-cpp-macro-expansion-with-limitation.d/args.ctags @@ -0,0 +1,3 @@ +--param-CPreProcessor._expand=1 +--fields-CPreProcessor=+{macrodef} +--fields=+{language}{signature} diff --git a/Units/parser-asm.r/asm-cpp-macro-expansion-with-limitation.d/expected.tags b/Units/parser-asm.r/asm-cpp-macro-expansion-with-limitation.d/expected.tags new file mode 100644 index 0000000000..47ee6cfafc --- /dev/null +++ b/Units/parser-asm.r/asm-cpp-macro-expansion-with-limitation.d/expected.tags @@ -0,0 +1,3 @@ +X input.S /^#define X /;" d language:CPreProcessor file: macrodef:Y +Y input.S /^#define Y Y$/;" d language:CPreProcessor file: macrodef:Y +Y input.S /^X:$/;" l language:Asm diff --git a/Units/parser-asm.r/asm-cpp-macro-expansion-with-limitation.d/input.S b/Units/parser-asm.r/asm-cpp-macro-expansion-with-limitation.d/input.S new file mode 100644 index 0000000000..df92a3c967 --- /dev/null +++ b/Units/parser-asm.r/asm-cpp-macro-expansion-with-limitation.d/input.S @@ -0,0 +1,4 @@ +#define X Y +#define Y Y +X: + nop diff --git a/parsers/asm.c b/parsers/asm.c index 66755a8bd7..1c6d29f03a 100644 --- a/parsers/asm.c +++ b/parsers/asm.c @@ -318,11 +318,11 @@ static const unsigned char *readOperator ( // We stop applying macro replacements if the unget buffer gets too big // as it is a sign of recursive macro expansion -#define ASM_SCRIPT_PARSER_MAXIMUM_UNGET_BUFFER_SIZE_FOR_MACRO_REPLACEMENTS 65536 +#define ASM_PARSER_MAXIMUM_UNGET_BUFFER_SIZE_FOR_MACRO_REPLACEMENTS 65536 // We stop applying macro replacements if a macro is used so many // times in a recursive macro expansion. -#define ASM_SCRIPT_PARSER_MAXIMUM_MACRO_USE_COUNT 8 +#define ASM_PARSER_MAXIMUM_MACRO_USE_COUNT 8 static bool collectCppMacroArguments (ptrArray *args) { @@ -429,6 +429,9 @@ static bool processCppMacroX (vString *identifier, int lastChar, vString *line) if (!macroInfo) goto out; + if(macroInfo && (macroInfo->useCount >= ASM_PARSER_MAXIMUM_MACRO_USE_COUNT)) + goto out; + if (lastChar != EOF) cppUngetc (lastChar); diff --git a/parsers/ldscript.c b/parsers/ldscript.c index 79282f6bf0..8abb51d233 100644 --- a/parsers/ldscript.c +++ b/parsers/ldscript.c @@ -346,8 +346,11 @@ static bool expandCppMacro (cppMacroInfo *macroInfo) } #ifdef DO_TRACING - for (int i = 0; i < ptrArrayCount(args); i++) - TRACE_PRINT("[%d] %s", i, (const char *)ptrArrayItem (args, i)); + if (args) + { + for (int i = 0; i < ptrArrayCount(args); i++) + TRACE_PRINT("[%d] %s", i, (const char *)ptrArrayItem (args, i)); + } #endif cppBuildMacroReplacementWithPtrArrayAndUngetResult (macroInfo, args);