ref: de7d1facf3609165bb8b8bb96e19022ef4f46dfc
parent: 310d34c655cd06dfdc579e29b4c1e3f831f8bd66
author: ISSOtm <eldredhabert0@gmail.com>
date: Sat Apr 3 14:31:19 EDT 2021
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.
--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -761,7 +761,10 @@
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); \