diff --git a/src/asm/asmy.y b/src/asm/asmy.y index 1ea0a672..6264f74e 100644 --- a/src/asm/asmy.y +++ b/src/asm/asmy.y @@ -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 ) { @@ -221,8 +222,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 ) { diff --git a/src/asm/rpn.c b/src/asm/rpn.c index 3a8dba27..2bc9d94c 100644 --- a/src/asm/rpn.c +++ b/src/asm/rpn.c @@ -316,6 +316,9 @@ rpn_DIV(struct Expression * expr, struct Expression * src1, struct Expression * src2) { joinexpr(); + if (src2->nVal == 0) { + fatalerror("division by zero"); + } expr->nVal = (expr->nVal / src2->nVal); pushbyte(expr, RPN_DIV); } @@ -325,6 +328,9 @@ rpn_MOD(struct Expression * expr, struct Expression * src1, struct Expression * src2) { joinexpr(); + if (src2->nVal == 0) { + fatalerror("division by zero"); + } expr->nVal = (expr->nVal % src2->nVal); pushbyte(expr, RPN_MOD); }