Prevent declaring arrays that the compiler is too buggy to handle (bug 4977, r=fyren).
authorDavid Anderson <dvander@alliedmods.net>
Wed Jul 06 17:56:03 2011 -0400 (2011-07-06)
changeset 33377fb572471a78
parent 3336 f15aa1370640
child 3338 294fded6a0d0
Prevent declaring arrays that the compiler is too buggy to handle (bug 4977, r=fyren).
sourcepawn/compiler/sc1.c
sourcepawn/compiler/sc5.c
sourcepawn/compiler/sc5.scp
     1.1 --- a/sourcepawn/compiler/sc1.c	Wed Jul 06 17:55:14 2011 -0400
     1.2 +++ b/sourcepawn/compiler/sc1.c	Wed Jul 06 17:56:03 2011 -0400
     1.3 @@ -2711,6 +2711,23 @@
     1.4      eq_match_override = matchtoken('=');
     1.5    }
     1.6  
     1.7 +  if (numdim > 2) {
     1.8 +    int d, hasEmpty = 0;
     1.9 +    for (d = 0; d < numdim; d++) {
    1.10 +      if (dim[d] == 0)
    1.11 +        hasEmpty++;
    1.12 +    }
    1.13 +    /* Work around ambug 4977 where indirection vectors are computed wrong. */
    1.14 +    if (hasEmpty && hasEmpty < numdim-1 && dim[numdim-1]) {
    1.15 +      error(101);
    1.16 +      /* This will assert with something like [2][][256] from a separate bug.
    1.17 +       * To prevent this assert, automatically wipe the rest of the dims.
    1.18 +       */
    1.19 +      for (d = 0; d < numdim - 1; d++)
    1.20 +        dim[d] = 0;
    1.21 +    }
    1.22 +  }
    1.23 +
    1.24    if (!eq_match_override) {
    1.25      assert(ident!=iARRAY || numdim>0);
    1.26      if (ident==iARRAY && dim[numdim-1]==0) {
     2.1 --- a/sourcepawn/compiler/sc5.c	Wed Jul 06 17:55:14 2011 -0400
     2.2 +++ b/sourcepawn/compiler/sc5.c	Wed Jul 06 17:56:03 2011 -0400
     2.3 @@ -74,7 +74,6 @@
     2.4  static short lastfile;
     2.5    char *msg,*pre;
     2.6    va_list argptr;
     2.7 -  char string[128];
     2.8  
     2.9    /* errflag is reset on each semicolon.
    2.10     * In a two-pass compiler, an error should not be reported twice. Therefore
    2.11 @@ -107,8 +106,6 @@
    2.12      warnnum++;
    2.13    } /* if */
    2.14  
    2.15 -  strexpand(string,(unsigned char *)msg,sizeof string,SCPACK_TABLE);
    2.16 -
    2.17    assert(errstart<=fline);
    2.18    if (errline>0)
    2.19      errstart=errline;
    2.20 @@ -118,7 +115,7 @@
    2.21    va_start(argptr,number);
    2.22    if (strlen(errfname)==0) {
    2.23      int start= (errstart==errline) ? -1 : errstart;
    2.24 -    if (pc_error(number,string,inpfname,start,errline,argptr)) {
    2.25 +    if (pc_error(number,msg,inpfname,start,errline,argptr)) {
    2.26        if (outf!=NULL) {
    2.27          pc_closeasm(outf,TRUE);
    2.28          outf=NULL;
    2.29 @@ -132,7 +129,7 @@
    2.30          fprintf(fp,"%s(%d -- %d) : %s %03d: ",inpfname,errstart,errline,pre,number);
    2.31        else
    2.32          fprintf(fp,"%s(%d) : %s %03d: ",inpfname,errline,pre,number);
    2.33 -      vfprintf(fp,string,argptr);
    2.34 +      vfprintf(fp,msg,argptr);
    2.35        fclose(fp);
    2.36      } /* if */
    2.37    } /* if */
     3.1 --- a/sourcepawn/compiler/sc5.scp	Wed Jul 06 17:55:14 2011 -0400
     3.2 +++ b/sourcepawn/compiler/sc5.scp	Wed Jul 06 17:56:03 2011 -0400
     3.3 @@ -38,7 +38,7 @@
     3.4  /*-*SCPACK end of pair table, do not change or remove this line */
     3.5  
     3.6  static char *errmsg[] = {
     3.7 -#ifdef SCPACK
     3.8 +#if 1
     3.9  /*001*/  "expected token: \"%s\", but found \"%s\"\n",
    3.10  /*002*/  "only a single statement (or expression) can follow each \"case\"\n",
    3.11  /*003*/  "declaration of a local variable must appear in a compound block\n",
    3.12 @@ -138,7 +138,8 @@
    3.13  /*097*/  "symbol \"%s\" does not have a matching type\n",
    3.14  /*098*/  "struct requires unique struct name\n",
    3.15  /*099*/  "member \"%s\" appears more than once in struct \"%s\"\n",
    3.16 -/*100*/  "function prototypes do not match\n"
    3.17 +/*100*/  "function prototypes do not match\n",
    3.18 +/*101*/  "specify either all dimensions or only the last dimension\n"
    3.19  #else
    3.20    "\271pect\236\305k\212:\231\320bu\202fo\217\207\215\012",
    3.21    "\201l\224\251s\203g\362\317e\234\202(\260\374\201) c\352f\241\345w ea\261 \042c\361e\042\012",
    3.22 @@ -244,7 +245,7 @@
    3.23         };
    3.24  
    3.25  static char *fatalmsg[] = {
    3.26 -#ifdef SCPACK
    3.27 +#if 1
    3.28  /*120*/  "cannot read from file: \"%s\"\n",
    3.29  /*121*/  "cannot write to file: \"%s\"\n",
    3.30  /*122*/  "table overflow: \"%s\"\n",
    3.31 @@ -280,7 +281,7 @@
    3.32         };
    3.33  
    3.34  static char *warnmsg[] = {
    3.35 -#ifdef SCPACK
    3.36 +#if 1
    3.37  /*200*/  "symbol \"%s\" is truncated to %d characters\n",
    3.38  /*201*/  "redefinition of constant/macro (symbol \"%s\")\n",
    3.39  /*202*/  "number of arguments does not match definition\n",