mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Fix possible capture buffer size overflow
Attempt to grow it to the max size first. Seriously, if this triggers, *how*
This commit is contained in:
@@ -503,6 +503,11 @@ void lexer_ToggleStringExpansion(bool enable)
|
|||||||
|
|
||||||
static void reallocCaptureBuf(void)
|
static void reallocCaptureBuf(void)
|
||||||
{
|
{
|
||||||
|
if (lexerState->captureCapacity == SIZE_MAX)
|
||||||
|
fatalerror("Cannot grow capture buffer past %zu bytes", SIZE_MAX);
|
||||||
|
else if (lexerState->captureCapacity > SIZE_MAX / 2)
|
||||||
|
lexerState->captureCapacity = SIZE_MAX;
|
||||||
|
else
|
||||||
lexerState->captureCapacity *= 2;
|
lexerState->captureCapacity *= 2;
|
||||||
lexerState->captureBuf = realloc(lexerState->captureBuf, lexerState->captureCapacity);
|
lexerState->captureBuf = realloc(lexerState->captureBuf, lexerState->captureCapacity);
|
||||||
if (!lexerState->captureBuf)
|
if (!lexerState->captureBuf)
|
||||||
|
|||||||
Reference in New Issue
Block a user