From 4c8d56c51115f3f3eefbae6cff38cfd86f46df15 Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Sat, 24 Nov 2018 20:08:42 +0700 Subject: [PATCH] __emit: Issue an error if the stack offset/data address is not a multiple of cell size --- source/compiler/sc1.c | 20 ++++++++++++++------ source/compiler/sc5.c | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index c40eefe..365d486 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -6221,7 +6221,6 @@ static void SC_FASTCALL emit_param_data(emit_outval *p) tok=lex(&val,&str); switch (tok) { case tNUMBER: - p->value.ucell=(ucell)val; break; case tSYMBOL: sym=findloc(str); @@ -6239,7 +6238,7 @@ static void SC_FASTCALL emit_param_data(emit_outval *p) sym=findglb(str,sSTATIC); if (sym==NULL) { error(17,str); /* undefined symbol */ - break; + return; } /* if */ markusage(sym,uREAD | uWRITTEN); if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) { @@ -6247,12 +6246,17 @@ static void SC_FASTCALL emit_param_data(emit_outval *p) goto invalid_token; } /* if */ } /* if */ - p->value.ucell=(ucell)sym->addr; + val=sym->addr; break; default: invalid_token: emit_invalid_token(teDATA,tok); + return; } /* switch */ + if ((val % sizeof(cell))==0) + p->value.ucell=(ucell)val; + else + error(11); /* must be a multiple of cell size */ } static void SC_FASTCALL emit_param_local(emit_outval *p) @@ -6266,7 +6270,6 @@ static void SC_FASTCALL emit_param_local(emit_outval *p) tok=lex(&val,&str); switch (tok) { case tNUMBER: - p->value.ucell=(ucell)val; break; case tSYMBOL: sym=findloc(str); @@ -6285,18 +6288,23 @@ static void SC_FASTCALL emit_param_local(emit_outval *p) if (sym==NULL) { undefined_sym: error(17,str); /* undefined symbol */ - break; + return; } /* if */ markusage(sym,uREAD | uWRITTEN); if (sym->ident!=iCONSTEXPR) goto undefined_sym; } /* if */ - p->value.ucell=(ucell)sym->addr; + val=sym->addr; break; default: invalid_token: emit_invalid_token(tSYMBOL,tok); + return; } /* switch */ + if ((val % sizeof(cell))==0) + p->value.ucell = (ucell)val; + else + error(11); /* must be a multiple of cell size */ } static void SC_FASTCALL emit_param_label(emit_outval *p) diff --git a/source/compiler/sc5.c b/source/compiler/sc5.c index 47772a2..4ba4555 100644 --- a/source/compiler/sc5.c +++ b/source/compiler/sc5.c @@ -50,7 +50,7 @@ static char *errmsg[] = { /*008*/ "must be a constant expression; assumed zero\n", /*009*/ "invalid array size (negative, zero or out of bounds)\n", /*010*/ "invalid function or declaration\n", -/*011*/ "invalid outside functions\n", +/*011*/ "stack offset/data address must be a multiple of cell size\n", /*012*/ "invalid function call, not a valid address\n", /*013*/ "no entry point (no public functions)\n", /*014*/ "invalid statement; not in switch\n",