mirror of
https://github.com/gbdev/rgbds.git
synced 2026-10-04 19:25:43 +00:00
Don't segfault on null bytes in REPTs and MACROs
Previously, the copyrept() and copymacro() functions would halt their first loop (in which they determine the length of the block) prematurely, causing an underflow when setting len, eventually causing memory issues. Whilst this doesn’t solve the len underflow entirely (e.g. if the file ends immediately without an ENDR/ENDM), it should help with this exact scenario of null bytes (as #50).
This commit is contained in:
1 parent
0a66e14307
commit
951c9b66f4
1 file changed
+4
-2
+4
-2
@@ -142,8 +142,9 @@ void copyrept( void )
|
||||
{
|
||||
SLONG level=1, len, instring=0;
|
||||
char *src=pCurrentBuffer->pBuffer;
|
||||
char *bufferEnd = pCurrentBuffer->pBufferStart + pCurrentBuffer->nBufferSize;
|
||||
|
||||
while( *src && level )
|
||||
while( src < bufferEnd && level )
|
||||
{
|
||||
if( instring==0 )
|
||||
{
|
||||
@@ -217,8 +218,9 @@ void copymacro( void )
|
||||
{
|
||||
SLONG level=1, len, instring=0;
|
||||
char *src=pCurrentBuffer->pBuffer;
|
||||
char *bufferEnd = pCurrentBuffer->pBufferStart + pCurrentBuffer->nBufferSize;
|
||||
|
||||
while( *src && level )
|
||||
while( src < bufferEnd && level )
|
||||
{
|
||||
if( instring==0 )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user