Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C,Asm,LdScript: minor fixes #3623

Merged
merged 2 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--param-CPreProcessor._expand=1
--fields-CPreProcessor=+{macrodef}
--fields=+{language}{signature}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#define X Y
#define Y Y
X:
nop
7 changes: 5 additions & 2 deletions parsers/asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);

Expand Down
7 changes: 5 additions & 2 deletions parsers/ldscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down