mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
reserveSpace: don't assume one doubling is enough
This commit is contained in:
@@ -46,17 +46,19 @@ static uint8_t *reserveSpace(struct Expression *expr, uint32_t size)
|
|||||||
/* If there isn't enough room to reserve the space, realloc */
|
/* If there isn't enough room to reserve the space, realloc */
|
||||||
if (!expr->tRPN)
|
if (!expr->tRPN)
|
||||||
expr->nRPNCapacity = 256; /* Initial size */
|
expr->nRPNCapacity = 256; /* Initial size */
|
||||||
else if (expr->nRPNCapacity >= MAXRPNLEN)
|
while (expr->nRPNCapacity - expr->nRPNLength < size) {
|
||||||
/*
|
if (expr->nRPNCapacity >= MAXRPNLEN)
|
||||||
* To avoid generating humongous object files, cap the
|
/*
|
||||||
* size of RPN expressions
|
* To avoid generating humongous object files, cap the
|
||||||
*/
|
* size of RPN expressions
|
||||||
fatalerror("RPN expression cannot grow larger than "
|
*/
|
||||||
EXPAND_AND_STR(MAXRPNLEN) " bytes\n");
|
fatalerror("RPN expression cannot grow larger than "
|
||||||
else if (expr->nRPNCapacity > MAXRPNLEN / 2)
|
EXPAND_AND_STR(MAXRPNLEN) " bytes\n");
|
||||||
expr->nRPNCapacity = MAXRPNLEN;
|
else if (expr->nRPNCapacity > MAXRPNLEN / 2)
|
||||||
else
|
expr->nRPNCapacity = MAXRPNLEN;
|
||||||
expr->nRPNCapacity *= 2;
|
else
|
||||||
|
expr->nRPNCapacity *= 2;
|
||||||
|
}
|
||||||
expr->tRPN = realloc(expr->tRPN, expr->nRPNCapacity);
|
expr->tRPN = realloc(expr->tRPN, expr->nRPNCapacity);
|
||||||
|
|
||||||
if (!expr->tRPN)
|
if (!expr->tRPN)
|
||||||
|
|||||||
@@ -27,3 +27,10 @@ X EQUS "{X7E}"
|
|||||||
X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X
|
X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X+X
|
||||||
|
|
||||||
x: db 0
|
x: db 0
|
||||||
|
|
||||||
|
; this tests long RPN expressions being used as the RHS, as this once triggered
|
||||||
|
; a realloc bug
|
||||||
|
db 1+(x+X)
|
||||||
|
|
||||||
|
; likewise, a long symbol could result in an insufficient *initial* allocation
|
||||||
|
db A00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000+0+0
|
||||||
|
|||||||
Reference in New Issue
Block a user