mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
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:
@@ -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); \
|
||||||
|
|||||||
Reference in New Issue
Block a user