Add assertion that an expansion's total len doesn't overflow

Typically not needed because the recursion depth limit should prevent it,
but it might help debug weird lexer issues.
This commit is contained in:
ISSOtm
2021-04-03 18:31:19 +02:00
parent 310d34c655
commit de7d1facf3

View File

@@ -761,7 +761,10 @@ static void beginExpansion(size_t distance, uint8_t skip, char const *str, bool
struct Expansion *parent = NULL; struct Expansion *parent = NULL;
unsigned int depth = 0; unsigned int depth = 0;
#define LOOKUP_PRE_NEST(exp) (exp)->totalLen += size - skip #define LOOKUP_PRE_NEST(exp) do { \
assert((exp)->totalLen <= SIZE_MAX - (size - skip)); \
(exp)->totalLen += size - skip; \
} while (0)
#define LOOKUP_POST_NEST(exp) do { \ #define LOOKUP_POST_NEST(exp) do { \
if (name && ++depth >= nMaxRecursionDepth) \ if (name && ++depth >= nMaxRecursionDepth) \
fatalerror("Recursion limit (%zu) exceeded\n", nMaxRecursionDepth); \ fatalerror("Recursion limit (%zu) exceeded\n", nMaxRecursionDepth); \