diff --git a/assemble.c b/assemble.c index 6920d90..afb9261 100644 --- a/assemble.c +++ b/assemble.c @@ -344,6 +344,10 @@ static int assemble( return 0; case P_SAVE: + if (sect_sp >= SECT_STACK_SIZE - 1) { + report(stack->top, "Too many saved sections for .SAVE\n"); + return 0; + } sect_sp++; sect_stack[sect_sp] = current_pc->section; return 1; @@ -354,7 +358,7 @@ static int assemble( return 0; } else { go_section(tr, sect_stack[sect_sp]); - sect_sp++; + sect_sp--; } return 1; diff --git a/assemble_globals.c b/assemble_globals.c index 18c7f32..b1ea31a 100644 --- a/assemble_globals.c +++ b/assemble_globals.c @@ -42,7 +42,7 @@ int nr_mlbs = 0; /* Number of macro libraries */ COND conds[MAX_CONDS]; /* Stack of recent conditions */ int last_cond; /* 0 means no stacked cond. */ -SECTION *sect_stack[32]; /* 32 saved sections */ +SECTION *sect_stack[SECT_STACK_SIZE]; /* 32 saved sections */ int sect_sp; /* Stack pointer */ char *module_name = NULL; /* The module name (taken from the 'TITLE'); */ diff --git a/assemble_globals.h b/assemble_globals.h index c657b4e..0cda4e6 100644 --- a/assemble_globals.h +++ b/assemble_globals.h @@ -20,6 +20,7 @@ typedef struct cond { int line; } COND; +#define SECT_STACK_SIZE 32 #ifndef ASSEMBLE_GLOBALS__C /* GLOBAL VARIABLES */ @@ -51,7 +52,7 @@ extern int nr_mlbs; /* Number of macro libraries */ extern COND conds[MAX_CONDS]; /* Stack of recent conditions */ extern int last_cond; /* 0 means no stacked cond. */ -extern SECTION *sect_stack[32]; /* 32 saved sections */ +extern SECTION *sect_stack[SECT_STACK_SIZE]; /* 32 saved sections */ extern int sect_sp; /* Stack pointer */ extern char *module_name; /* The module name (taken from the 'TITLE'); */