mirror of
https://github.com/gbdev/rgbds.git
synced 2026-10-04 03:05:36 +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:
1 parent
310d34c655
commit
de7d1facf3
1 file changed
+4
-1
+4
-1
@@ -761,7 +761,10 @@ static void beginExpansion(size_t distance, uint8_t skip, char const *str, bool
|
||||
struct Expansion *parent = NULL;
|
||||
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 { \
|
||||
if (name && ++depth >= nMaxRecursionDepth) \
|
||||
fatalerror("Recursion limit (%zu) exceeded\n", nMaxRecursionDepth); \
|
||||
|
||||
Reference in new issue
Block a user