commit 33e77e261c4ae2c84ef11e2c1dd529b5e372f062
parent a373939544b3877ed2678b92a4b7264e003c6dd0
Author: Claude Heiland-Allen <claude@mathr.co.uk>
Date: Tue, 26 Oct 2021 16:59:58 +0100
uxnasm errors-out if too many macros
Diffstat:
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/uxnasm.c b/src/uxnasm.c
@@ -15,6 +15,7 @@ WITH REGARD TO THIS SOFTWARE.
#define LENGTH 0x10000
#define LABELS 512
+#define MACROS 256
typedef unsigned char Uint8;
typedef signed char Sint8;
@@ -31,10 +32,10 @@ typedef struct {
} Label;
typedef struct {
- Uint8 data[LENGTH], mlen;
- Uint16 ptr, length, llen;
+ Uint8 data[LENGTH];
+ Uint16 ptr, length, llen, mlen;
Label labels[LABELS];
- Macro macros[256];
+ Macro macros[MACROS];
} Program;
Program p;
@@ -158,6 +159,8 @@ makemacro(char *name, FILE *f)
return error("Macro name is hex number", name);
if(findopcode(name) || scmp(name, "BRK", 4) || !slen(name) || scmp(name, "include", 8))
return error("Macro name is invalid", name);
+ if(p.mlen == MACROS)
+ return error("Too many macros", name);
m = &p.macros[p.mlen++];
scpy(name, m->name, 64);
while(fscanf(f, "%63s", word) == 1) {