Showing with 10 additions and 1 deletion.
  1. +8 −1 src/macro.c
  2. +2 −0 src/magicport.json
9 changes: 8 additions & 1 deletion src/macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <ctype.h>
#include <assert.h>

#include "errors.h"
#include "rmem.h"
#include "root.h"

Expand Down Expand Up @@ -232,9 +233,15 @@ void Macro::expand(OutBuffer *buf, size_t start, size_t *pend,
printf("Buf is: '%.*s'\n", *pend - start, buf->data + start);
#endif

// limit recursive expansion
static int nest;
if (nest > 100) // limit recursive expansion
static const int nestLimit = 1000;
if (nest > nestLimit)
{
error(Loc(), "DDoc macro expansion limit exceeded; more than %d "
"expansions.", nestLimit);
return;
}
nest++;

size_t end = *pend;
Expand Down
2 changes: 2 additions & 0 deletions src/magicport.json
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,8 @@
"core.stdc.ctype",
"core.stdc.string",
"doc",
"errors",
"globals",
"root.outbuffer",
"root.rmem",
"utf"
Expand Down