From 38372c59edb070d2c0320d21c6cf898e118e3e26 Mon Sep 17 00:00:00 2001 From: Ben10do Date: Thu, 2 Feb 2017 16:27:53 +0000 Subject: [PATCH] Verify that IFs, REPTs and MACROs are terminated Ensure that IF constructs, REPT blocks, and MACRO defintions are terminated with ENDC, ENDR, or ENDM respectively. If they are not, print an error and stop assembly. As well as aiding a forgetful programmer, this reduces the risk of memory problems if the file ends less than four bytes after the block starts. --- src/asm/asmy.y | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/asm/asmy.y b/src/asm/asmy.y index 29dd9f01..c06d47e3 100644 --- a/src/asm/asmy.y +++ b/src/asm/asmy.y @@ -182,6 +182,10 @@ void copyrept( void ) } } + if (level != 0) { + fatalerror("Unterminated REPT block"); + } + len=src-pCurrentBuffer->pBuffer-4; src=pCurrentBuffer->pBuffer; @@ -257,6 +261,10 @@ void copymacro( void ) } } + if (level != 0) { + fatalerror("Unterminated MACRO definition"); + } + len=src-pCurrentBuffer->pBuffer-4; src=pCurrentBuffer->pBuffer; @@ -348,6 +356,10 @@ void if_skip_to_else( void ) } } + if (level != 0) { + fatalerror("Unterminated IF construct"); + } + len=src-pCurrentBuffer->pBuffer; yyskipbytes( len ); @@ -403,6 +415,10 @@ void if_skip_to_endc( void ) } } + if (level != 0) { + fatalerror("Unterminated IF construct"); + } + len=src-pCurrentBuffer->pBuffer; yyskipbytes( len );