From 41dfdc7f59d3b8eb2d56947120059c642e17098a Mon Sep 17 00:00:00 2001 From: Arkshine Date: Mon, 18 May 2015 23:59:58 +0200 Subject: [PATCH] Compiler: Prevent declaring arrays that the compiler is too buggy to handle AM Bug 7977: https://bugs.alliedmods.net/show_bug.cgi?id=4977 --- compiler/libpc300/sc1.c | 17 +++++++++++++++++ compiler/libpc300/sc5-in.scp | 1 + 2 files changed, 18 insertions(+) diff --git a/compiler/libpc300/sc1.c b/compiler/libpc300/sc1.c index fc15e124..fdaa1633 100755 --- a/compiler/libpc300/sc1.c +++ b/compiler/libpc300/sc1.c @@ -2202,6 +2202,23 @@ static void initials2(int ident,int tag,cell *size,int dim[],int numdim, eq_match_override = matchtoken('='); } + if (numdim > 2) { + int d, hasEmpty = 0; + for (d = 0; d < numdim; d++) { + if (dim[d] == 0) + hasEmpty++; + } + /* Work around ambug 4977 where indirection vectors are computed wrong. */ + if (hasEmpty && hasEmpty < numdim-1 && dim[numdim-1]) { + error(112); + /* This will assert with something like [2][][256] from a separate bug. + * To prevent this assert, automatically wipe the rest of the dims. + */ + for (d = 0; d < numdim - 1; d++) + dim[d] = 0; + } + } + if (!eq_match_override) { assert(ident!=iARRAY || numdim>0); if (ident==iARRAY && dim[numdim-1]==0) { diff --git a/compiler/libpc300/sc5-in.scp b/compiler/libpc300/sc5-in.scp index 8d840fe5..4f77d962 100644 --- a/compiler/libpc300/sc5-in.scp +++ b/compiler/libpc300/sc5-in.scp @@ -129,6 +129,7 @@ static char *fatalmsg[] = { /*109*/ "invalid path: \"%s\"\n", /*110*/ "assertion failed: %s\n", /*111*/ "user error: %s\n", +/*112*/ "specify either all dimensions or only the last dimension\n" }; static char *warnmsg[] = {