Skip to content

Commit

Permalink
print an error when the macro expansion limit is exceeded
Browse files Browse the repository at this point in the history
  • Loading branch information
aG0aep6G committed Jul 5, 2015
1 parent 3f444af commit da73aae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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 > 1000) // 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

0 comments on commit da73aae

Please sign in to comment.