Fix bug with .SAVE and .RESTORE

.SAVE didn't check for  stack overflow.
.RESTORE moved the stack pointer in the wrong direction.
This commit is contained in:
Olaf Seibert 2015-05-09 12:51:31 +02:00
parent b4d3c9a094
commit 20f25b9dd9
3 changed files with 8 additions and 3 deletions

View File

@ -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;

View File

@ -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'); */

View File

@ -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'); */