From 6d81be8ba7ccb1585185223560886ca9fcee45c2 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sat, 15 May 2021 19:05:04 +0700 Subject: [PATCH 1/2] Ralocate fatal errors to a range of 300+ --- source/compiler/libpawnc.c | 10 +++-- source/compiler/sc1.c | 68 ++++++++++++++++----------------- source/compiler/sc2.c | 44 ++++++++++----------- source/compiler/sc3.c | 4 +- source/compiler/sc5.c | 78 +++++++++++++++++++------------------- source/compiler/sc6.c | 10 ++--- source/compiler/sc7.c | 8 ++-- source/compiler/sclist.c | 12 +++--- source/compiler/scstate.c | 6 +-- 9 files changed, 121 insertions(+), 119 deletions(-) diff --git a/source/compiler/libpawnc.c b/source/compiler/libpawnc.c index 9f55deac..1817b0c6 100644 --- a/source/compiler/libpawnc.c +++ b/source/compiler/libpawnc.c @@ -134,10 +134,12 @@ static char *prefix[3]={ "error", "fatal error", "warning" }; if (number!=0) { char *pre; - pre=prefix[number/100]; - if (number>=200 && pc_geterrorwarnings()){ - pre=prefix[0]; - } + if (number<200 || (number<300 && pc_geterrorwarnings())) + pre="error"; + else if (number<300) + pre="warning"; + else + pre="fatal error"; if (firstline>=0) fprintf(stderr,"%s(%d -- %d) : %s %03d: ",filename,firstline,lastline,pre,number); else diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index a50409ea..68603c8b 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -549,10 +549,10 @@ int pc_compile(int argc, char *argv[]) /* allocate memory for fixed tables */ inpfname=(char*)malloc(_MAX_PATH); if (inpfname==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ litq=(cell*)malloc(litmax*sizeof(cell)); if (litq==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ /* inptfname may be used in error(), fill it with zeros */ memset(inpfname,0,_MAX_PATH); @@ -580,7 +580,7 @@ int pc_compile(int argc, char *argv[]) lcl_tabsize=sc_tabsize; #if !defined NO_CODEPAGE if (!cp_set(codepage)) /* set codepage */ - error(108); /* codepage mapping file not found */ + error(308); /* codepage mapping file not found */ #endif /* optionally create a temporary input file that is a collection of all * input files @@ -597,7 +597,7 @@ int pc_compile(int argc, char *argv[]) fsrc=(FILE*)pc_opensrc(sname); if (fsrc==NULL) { strcpy(inpfname,sname); /* avoid invalid filename */ - error(100,sname); + error(300,sname); } /* if */ pc_writesrc(ftmp,(unsigned char*)"#file \""); pc_writesrc(ftmp,(unsigned char*)sname); @@ -615,18 +615,18 @@ int pc_compile(int argc, char *argv[]) } /* if */ inpf_org=(FILE*)pc_opensrc(inpfname); if (inpf_org==NULL) - error(100,inpfname); + error(300,inpfname); freading=TRUE; outf=(FILE*)pc_openasm(outfname); /* first write to assembler file (may be temporary) */ if (outf==NULL) - error(101,outfname); + error(301,outfname); /* immediately open the binary file, for other programs to check */ if (sc_asmfile || sc_listing) { binf=NULL; } else { binf=(FILE*)pc_openbin(binfname); if (binf==NULL) - error(101,binfname); + error(301,binfname); } /* if */ setconstants(); /* set predefined constants and tagnames */ for (i=0; i INT_MAX) - error(105); /* overflow, exceeding capacity */ + error(305); /* overflow, exceeding capacity */ #endif if (ispublic) error(56,name); /* arrays cannot be public */ @@ -2432,7 +2432,7 @@ static int declloc(int fstatic) size=needsub(&idxtag[numdim],&enumroot); /* get size; size==0 for "var[]" */ #if INT_MAX < LONG_MAX if (size > INT_MAX) - error(105); /* overflow, exceeding capacity */ + error(305); /* overflow, exceeding capacity */ #endif dim[numdim++]=(int)size; } /* while */ @@ -3109,7 +3109,7 @@ static void decl_enum(int vclass,int fstatic) } /* if */ /* start a new list for the element names */ if ((enumroot=(constvalue_root*)malloc(sizeof(constvalue_root)))==NULL) - error(103); /* insufficient memory (fatal error) */ + error(303); /* insufficient memory (fatal error) */ memset(enumroot,0,sizeof(constvalue_root)); } /* if */ @@ -3316,7 +3316,7 @@ static void attachstatelist(symbol *sym, int state_id) constvalue *stateptr; if (sym->states==NULL) { if ((sym->states=(constvalue_root*)malloc(sizeof(constvalue_root)))==NULL) - error(103); /* insufficient memory (fatal error) */ + error(303); /* insufficient memory (fatal error) */ memset(sym->states,0,sizeof(constvalue_root)); } /* if */ /* see whether the id already exists (add new state only if it does not @@ -3791,7 +3791,7 @@ static void funcstub(int fnative) error(9); /* invalid array size */ #if INT_MAX < LONG_MAX if (size > INT_MAX) - error(105); /* overflow, exceeding capacity */ + error(305); /* overflow, exceeding capacity */ #endif dim[numdim++]=(int)size; } /* while */ @@ -4294,7 +4294,7 @@ static int declargs(symbol *sym,int chkshadow) /* redimension the argument list, add the entry */ arginfo* new_arglist=(arginfo*)realloc(sym->dim.arglist,(argcnt+2)*sizeof(arginfo)); if (new_arglist==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ sym->dim.arglist=new_arglist; memset(&sym->dim.arglist[argcnt+1],0,sizeof(arginfo)); /* keep the list terminated */ sym->dim.arglist[argcnt]=arg; @@ -4326,7 +4326,7 @@ static int declargs(symbol *sym,int chkshadow) /* redimension the argument list, add the entry iVARARGS */ arginfo* new_arglist=(arginfo*)realloc(sym->dim.arglist,(argcnt+2)*sizeof(arginfo)); if (new_arglist==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ sym->dim.arglist=new_arglist; memset(&sym->dim.arglist[argcnt+1],0,sizeof(arginfo)); /* keep the list terminated */ sym->dim.arglist[argcnt].ident=iVARARGS; @@ -4336,7 +4336,7 @@ static int declargs(symbol *sym,int chkshadow) sym->dim.arglist[argcnt].numtags=numtags; sym->dim.arglist[argcnt].tags=(int*)malloc(numtags*sizeof tags[0]); if (sym->dim.arglist[argcnt].tags==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ memcpy(sym->dim.arglist[argcnt].tags,tags,numtags*sizeof tags[0]); } else { if (argcnt>oldargcnt || sym->dim.arglist[argcnt].ident!=iVARARGS) @@ -4426,7 +4426,7 @@ static void doarg(char *name,int ident,int offset,int tags[],int numtags, size=needsub(&arg->idxtag[arg->numdim],&enumroot);/* may be zero here, it is a pointer anyway */ #if INT_MAX < LONG_MAX if (size > INT_MAX) - error(105); /* overflow, exceeding capacity */ + error(305); /* overflow, exceeding capacity */ #endif arg->dim[arg->numdim]=(int)size; arg->numdim+=1; @@ -4482,7 +4482,7 @@ static void doarg(char *name,int ident,int offset,int tags[],int numtags, /* save the name of the argument whose size id to take */ tokeninfo(&val,&symname); if ((arg->defvalue.size.symname=duplicatestring(symname)) == NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ arg->defvalue.size.level=0; if (size_tag_token==uSIZEOF) { while (matchtoken('[')) { @@ -4512,7 +4512,7 @@ static void doarg(char *name,int ident,int offset,int tags[],int numtags, arg->numtags=numtags; arg->tags=(int*)malloc(numtags*sizeof tags[0]); if (arg->tags==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ memcpy(arg->tags,tags,numtags*sizeof tags[0]); argsym=findloc(name); if (argsym!=NULL) { @@ -5104,7 +5104,7 @@ static long max_stacksize(symbol *root,int *recursion) symstack=(symbol **)malloc((numfunctions+1)*sizeof(symbol*)); rsymstack=(symbol **)malloc((numfunctions+1)*sizeof(symbol*)); if (symstack==NULL || rsymstack==NULL) - error(103); /* insufficient memory (fatal error) */ + error(303); /* insufficient memory (fatal error) */ memset(symstack,0,(numfunctions+1)*sizeof(symbol*)); memset(rsymstack,0,(numfunctions+1)*sizeof(symbol*)); @@ -5269,7 +5269,7 @@ static void scanloopvariables(symstate **loopvars,int dowhile) assert(num!=0); *loopvars=(symstate *)calloc((size_t)num,sizeof(symstate)); if (*loopvars==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ for (num=0,sym=start; sym!=NULL; num++,sym=sym->next) { /* If the variable already has the uLOOPVAR flag set (from being used @@ -5443,7 +5443,7 @@ static constvalue *insert_constval(constvalue *prev,constvalue *next, constvalue *cur; if ((cur=(constvalue*)malloc(sizeof(constvalue)))==NULL) - error(103); /* insufficient memory (fatal error) */ + error(303); /* insufficient memory (fatal error) */ memset(cur,0,sizeof(constvalue)); if (name!=NULL) { assert(strlen(name)=(wq+wqTABSZ-wqSIZE)) - error(102,"loop table"); /* loop table overflow (too many active loops)*/ + error(302,"loop table"); /* loop table overflow (too many active loops)*/ k=0; while (kstktop); newstack=(stkitem*)realloc(stack,newsize*sizeof(stkitem)); if (newstack==NULL) - error(102,"parser stack"); /* stack overflow (recursive include?) */ + error(302,"parser stack"); /* stack overflow (recursive include?) */ stack=newstack; stktop=newsize; } /* if */ @@ -147,12 +147,12 @@ static char extensions[][6] = { "", ".inc", ".p", ".pawn" }; ext_idx=0; path=(char *)malloc(strlen(name)+sizeof(extensions[0])); if (path==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ strcpy(path,name); real_path=(char *)malloc(strlen(name)+sizeof(extensions[0])); if (real_path==NULL) { free(path); - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ } /* if */ do { found=TRUE; @@ -198,7 +198,7 @@ static char extensions[][6] = { "", ".inc", ".p", ".pawn" }; PUSHSTK_I(fline); inpfname=path; /* set name of include file */ if (inpfname==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ inpf=fp; /* set input file pointer to include file */ fnumber++; fline=0; /* set current line number to 0 */ @@ -343,7 +343,7 @@ static void doinclude(int silent) if (result && pc_compat) add_constant(symname,1,sGLOBAL,0); else if (!result && !silent) - error(100,name); /* cannot read from ... (fatal error) */ + error(300,name); /* cannot read from ... (fatal error) */ } /* if */ } @@ -1086,7 +1086,7 @@ static int command(void) ret=CMD_IF; assert(iflevel>=0); if (iflevel>=sCOMP_STACK) - error(102,"Conditional compilation stack"); /* table overflow */ + error(302,"Conditional compilation stack"); /* table overflow */ iflevel++; if (SKIPPING) break; /* break out of switch */ @@ -1178,7 +1178,7 @@ static int command(void) free(inpfname); inpfname=duplicatestring(pathname); if (inpfname==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ insert_dbgfile(inpfname); } /* if */ } /* if */ @@ -1198,7 +1198,7 @@ static int command(void) /* nothing */; /* save start of expression */ preproc_expr(&val,NULL); /* get constant expression (or 0 on error) */ if (!val) - error(110,str); /* assertion failed */ + error(310,str); /* assertion failed */ check_empty(lptr); } /* if */ break; @@ -1222,7 +1222,7 @@ static int command(void) name[i]='\0'; } /* if */ if (!cp_set(name)) - error(108); /* codepage mapping file not found */ + error(308); /* codepage mapping file not found */ } else if (strcmp(str,"compress")==0) { preproc_expr(&val,NULL); sc_compress=(int)val; /* switch code packing on/off */ @@ -1248,7 +1248,7 @@ static int command(void) while (ptr>=pc_deprecate && *ptr<= ' ') *ptr--='\0'; } else { - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ } /* if */ lptr=(unsigned char*)strchr((char*)lptr,'\0'); /* skip to end (ignore "extra characters on line") */ } else if (strcmp(str,"dynamic")==0) { @@ -1552,7 +1552,7 @@ static int command(void) /* store matched pattern */ pattern=(char*)malloc(count+1); if (pattern==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ lptr=start; count=0; while (lptr!=end) { @@ -1586,7 +1586,7 @@ static int command(void) /* store matched substitution */ substitution=(char*)malloc(count+1); /* +1 for '\0' */ if (substitution==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ lptr=start; count=0; while (lptr!=end) { @@ -1645,12 +1645,12 @@ static int command(void) while (ptr >= usermsg && *ptr<=' ') *ptr--='\0'; if (tok==tpERROR) - error(111,usermsg); /* user error */ + error(311,usermsg); /* user error */ else error(237,usermsg); /* user warning */ free(usermsg); } else { - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ } /* if */ } /* if */ break; @@ -1824,7 +1824,7 @@ static int substpattern(unsigned char *line,size_t buffersize,char *pattern,char len=(int)(e-s); args[arg]=(unsigned char*)malloc(len+1); if (args[arg]==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ strlcpy((char*)args[arg],(char*)s,len+1); /* character behind the pattern was matched too */ if (*e==*p) { @@ -2547,14 +2547,14 @@ static void rectok(char *tokptr,int whitespace) if (pc_recstr==NULL) { pc_recstr=(char *)malloc((toklen+1)*sizeof(char)); if (pc_recstr==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ memcpy(pc_recstr,tokptr,toklen*sizeof(char)); pc_recstr[toklen]='\0'; } else { int oldlen=strlen(pc_recstr); char *newresctr=realloc(pc_recstr,(oldlen+(whitespace ? 1 : 0)+toklen+1)*sizeof(char)); if (newresctr==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ pc_recstr=newresctr; if (whitespace) pc_recstr[oldlen]=' '; @@ -2747,7 +2747,7 @@ static void chk_grow_litq(void) litgrow=litmax-litgrow; p=(cell *)realloc(litq,litmax*sizeof(cell)); if (p==NULL) - error(102,"literal table"); /* literal table overflow (fatal error) */ + error(302,"literal table"); /* literal table overflow (fatal error) */ litq=p; } /* if */ } @@ -3061,7 +3061,7 @@ static void symbol_cache_add(symbol *sym) if (pcache_sym==NULL) { if (hashtable_insert(&symbol_cache_ht,key,&sym)==0) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ return; } /* if */ cache_sym=*pcache_sym; @@ -3113,7 +3113,7 @@ static symbol *add_symbol(symbol *root,symbol *entry,int sort) root=root->next; if ((newsym=(symbol *)malloc(sizeof(symbol)))==NULL) - error(103); + error(303); memcpy(newsym,entry,sizeof(symbol)); newsym->next=root->next; root->next=newsym; @@ -3454,7 +3454,7 @@ SC_FUNC void memoizeassignments(int fromlevel,symstate **assignments) return; *assignments=(symstate *)calloc((size_t)num,sizeof(symstate)); if (*assignments==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ } /* if */ sym=&loctab; @@ -3598,7 +3598,7 @@ SC_FUNC symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag,i /* create an empty referrer list */ if ((refer=(symbol**)malloc(sizeof(symbol*)))==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ *refer=NULL; /* first fill in the entry */ diff --git a/source/compiler/sc3.c b/source/compiler/sc3.c index 11d7c03e..0dedc501 100644 --- a/source/compiler/sc3.c +++ b/source/compiler/sc3.c @@ -1983,7 +1983,7 @@ static int hier1(value *lval1) */ sym=fetchfunc(lastsymbol,0); if (sym==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ markusage(sym,uREAD); } else { return error(12); /* invalid function call */ @@ -2122,7 +2122,7 @@ static int primary(value *lval) assert(sc_status==statFIRST); sym=fetchfunc(st,0); if (sym==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ } /* if */ assert(sym!=NULL); assert(sym->ident==iFUNCTN || sym->ident==iREFFUNC); diff --git a/source/compiler/sc5.c b/source/compiler/sc5.c index ae126ec9..6332c34a 100644 --- a/source/compiler/sc5.c +++ b/source/compiler/sc5.c @@ -136,27 +136,6 @@ static char *errmsg[] = { /*094*/ "division by zero\n" }; -static char *fatalmsg[] = { -/*100*/ "cannot read from file: \"%s\"\n", -/*101*/ "cannot write to file: \"%s\"\n", -/*102*/ "table overflow: \"%s\"\n", - /* table can be: loop table - * literal table - * staging buffer - * option table (response file) - * peephole optimizer table - */ -/*103*/ "insufficient memory\n", -/*104*/ "invalid assembler instruction \"%s\"\n", -/*105*/ "numeric overflow, exceeding capacity\n", -/*106*/ "compiled script exceeds the maximum memory size (%ld bytes)\n", -/*107*/ "too many error messages on one line\n", -/*108*/ "codepage mapping file not found\n", -/*109*/ "invalid path: \"%s\"\n", -/*110*/ "assertion failed: %s\n", -/*111*/ "user error: %s\n" -}; - static char *warnmsg[] = { /*200*/ "symbol \"%s\" is truncated to %d characters\n", /*201*/ "redefinition of constant/macro (symbol \"%s\")\n", @@ -212,6 +191,27 @@ static char *warnmsg[] = { /*251*/ "none of the variables used in loop condition are modified in loop body\n" }; +static char *fatalmsg[] = { +/*300*/ "cannot read from file: \"%s\"\n", +/*301*/ "cannot write to file: \"%s\"\n", +/*302*/ "table overflow: \"%s\"\n", + /* table can be: loop table + * literal table + * staging buffer + * option table (response file) + * peephole optimizer table + */ +/*303*/ "insufficient memory\n", +/*304*/ "invalid assembler instruction \"%s\"\n", +/*305*/ "numeric overflow, exceeding capacity\n", +/*306*/ "compiled script exceeds the maximum memory size (%ld bytes)\n", +/*307*/ "too many error messages on one line\n", +/*308*/ "codepage mapping file not found\n", +/*309*/ "invalid path: \"%s\"\n", +/*310*/ "assertion failed: %s\n", +/*311*/ "user error: %s\n" +}; + static char *noticemsg[] = { /*001*/ "; did you mean \"%s\"?\n", /*002*/ "; state variable out of scope\n", @@ -256,18 +256,18 @@ static short lastfile; */ notice=(unsigned long)number >> (sizeof(long)*4); number&=(~(unsigned long)0) >> (sizeof(long)*4); - assert(number>0 && number<300); + assert(number>0 && number<300+arraysize(fatalmsg)); /* errflag is reset on each semicolon. * In a two-pass compiler, an error should not be reported twice. Therefore * the error reporting is enabled only in the second pass (and only when * actually producing output). Fatal errors may never be ignored. */ - if ((errflag || sc_status!=statWRITE) && (number<100 || number>=200)) + if ((errflag || sc_status!=statWRITE) && number<300) return 0; /* also check for disabled warnings */ - if (number>=200) { + if (number>=200 && number<300) { int index=(number-200)/8; int mask=1 << ((number-200)%8); if ((warnstack.disable[index] & mask)!=0) @@ -280,22 +280,22 @@ static short lastfile; pre=prefix[0]; errflag=TRUE; /* set errflag (skip rest of erroneous expression) */ errnum++; - } else if (number<200) { - assert(number>=100 && number<(100+arraysize(fatalmsg))); - msg=fatalmsg[number-100]; + } else if (number>=300) { + assert(number<(300+arraysize(fatalmsg))); + msg=fatalmsg[number-300]; pre=prefix[1]; errnum++; /* a fatal error also counts as an error */ - } else if (errwarn) { - assert(number>=200 && number<(200+arraysize(warnmsg))); - msg=warnmsg[number-200]; - pre=prefix[0]; - errflag=TRUE; - errnum++; } else { assert(number>=200 && number<(200+arraysize(warnmsg))); msg=warnmsg[number-200]; - pre=prefix[2]; - warnnum++; + if (errwarn) { + pre=prefix[0]; + errflag=TRUE; + errnum++; + } else { + pre=prefix[2]; + warnnum++; + } /* if */ } /* if */ if (notice!=0) { @@ -334,7 +334,7 @@ static short lastfile; } /* if */ va_end(argptr); - if ((number>=100 && number<200) || errnum>25){ + if (number>=300 || errnum>25) { if (errfname[0]=='\0') { va_start(argptr,number); pc_error(0,"\nCompilation aborted.\n\n",NULL,0,0,argptr); @@ -353,10 +353,10 @@ static short lastfile; errorcount=0; lastline=fline; lastfile=fcurrent; - if (number<200 || errwarn) + if (number<200 || number>=300 || errwarn) errorcount++; if (errorcount>=3) - error(107); /* too many error/warning messages on one line */ + error(307); /* too many error/warning messages on one line */ return 0; } @@ -429,7 +429,7 @@ void pc_pushwarnings(void) void *p; p=calloc(sizeof(struct s_warnstack),1); if (p==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ memmove(p,&warnstack,sizeof(struct s_warnstack)); warnstack.next=p; } diff --git a/source/compiler/sc6.c b/source/compiler/sc6.c index c58b7645..a9e6fe58 100644 --- a/source/compiler/sc6.c +++ b/source/compiler/sc6.c @@ -904,7 +904,7 @@ SC_FUNC int assemble(FILE *fout,FILE *fin) if (numnatives>0) { nativelist=(symbol **)malloc(numnatives*sizeof(symbol *)); if (nativelist==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ #if !defined NDEBUG memset(nativelist,0,numnatives*sizeof(symbol *)); /* for NULL checking */ #endif @@ -1026,7 +1026,7 @@ SC_FUNC int assemble(FILE *fout,FILE *fin) * if there are no labels */ lbltab=(cell *)malloc(sc_labnum*sizeof(cell)); if (lbltab==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ codeindex=0; pc_resetasm(fin); while (pc_readasm(fin,line,sizeof line)!=NULL) { @@ -1049,7 +1049,7 @@ SC_FUNC int assemble(FILE *fout,FILE *fin) i=findopcode(instr,(int)(params-instr)); if (opcodelist[i].name==NULL) { *params='\0'; - error(104,instr); /* invalid assembler instruction */ + error(304,instr); /* invalid assembler instruction */ } /* if */ if (opcodelist[i].segment==sIN_CSEG) codeindex+=opcodelist[i].func(NULL,skipwhitespace(params),opcodelist[i].opcode); @@ -1077,7 +1077,7 @@ SC_FUNC int assemble(FILE *fout,FILE *fin) assert(params>instr); i=findopcode(instr,(int)(params-instr)); if (opcodelist[i].name==NULL) - error(104, stripwhitespace(instr)); /* invalid assembler instruction */ + error(304, stripwhitespace(instr)); /* invalid assembler instruction */ if (opcodelist[i].segment==pass) opcodelist[i].func(fout,skipwhitespace(params),opcodelist[i].opcode); } /* while */ @@ -1098,7 +1098,7 @@ SC_FUNC int assemble(FILE *fout,FILE *fin) append_dbginfo(fout); /* optionally append debug file */ if (writeerror) - error(101,"disk full"); + error(301,"disk full"); /* adjust the header */ size=(int)hdr.cod; /* save, the value in the header may need to be swapped */ diff --git a/source/compiler/sc7.c b/source/compiler/sc7.c index 891d1472..88170869 100644 --- a/source/compiler/sc7.c +++ b/source/compiler/sc7.c @@ -1276,12 +1276,12 @@ static void grow_stgbuffer(char **buffer, int *curmax, int *growth, int required * over a few kBytes, there is probably a run-away expression */ if (requiredsize>sSTG_MAX) - error(102,"staging buffer"); /* staging buffer overflow (fatal error) */ + error(302,"staging buffer"); /* staging buffer overflow (fatal error) */ *curmax=requiredsize+*growth; *growth*=2; /* not as easy to grow this one by fibonacci, just double it */ p=(char *)realloc(*buffer,*curmax*sizeof(char)); if (p==NULL) - error(102,"staging buffer"); /* staging buffer overflow (fatal error) */ + error(302,"staging buffer"); /* staging buffer overflow (fatal error) */ *buffer=p; if (clear) **buffer='\0'; @@ -1476,7 +1476,7 @@ static int stgstring(char *start,char *end) /* allocate a argstack with sMAXARGS items */ stack=(argstack *)malloc(sMAXARGS*sizeof(argstack)); if (stack==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ reordered=TRUE; /* mark that the expression is reordered */ nest=1; /* nesting counter */ argc=0; /* argument counter */ @@ -1700,7 +1700,7 @@ static char *replacesequence(char *pattern,char symbols[MAX_OPT_VARS][MAX_ALIAS+ /* allocate a buffer to replace the sequence in */ if ((buffer=(char*)malloc(*repl_length))==NULL) - error(103); + error(303); /* replace the pattern into this temporary buffer */ lptr=buffer; diff --git a/source/compiler/sclist.c b/source/compiler/sclist.c index f15ddd57..1137c1b7 100644 --- a/source/compiler/sclist.c +++ b/source/compiler/sclist.c @@ -148,7 +148,7 @@ static stringlist *insert_string(stringlist *list,char *string) newlist.data=calloc(newlist.size,sizeof(char*)); newlist.strings=newlist.data; if (newlist.data==NULL) - error(103); /* insufficient memory (fatal error) */ + error(303); /* insufficient memory (fatal error) */ *list=newlist; } else if (list->length==list->size || list->length==list->data+list->size-list->strings) { @@ -158,12 +158,12 @@ static stringlist *insert_string(stringlist *list,char *string) newlist.data=realloc(list->data,newlist.size*sizeof(char*)); newlist.strings=newlist.data+(list->strings-list->data); if (newlist.data==NULL) - error(103); /* insufficient memory (fatal error) */ + error(303); /* insufficient memory (fatal error) */ memset(newlist.data+list->size,0,list->size/2*sizeof(char*)); *list=newlist; } /* if */ if ((list->strings[list->length]=duplicatestring(string))==NULL) - error(103); /* insufficient memory (fatal error) */ + error(303); /* insufficient memory (fatal error) */ list->length++; return list; } @@ -214,7 +214,7 @@ SC_FUNC stringpair *insert_alias(char *name,char *alias) assert(alias!=NULL); assert(strlen(alias)<=sNAMEMAX); if ((cur=insert_stringpair(&alias_tab,name,alias,strlen(name)))==NULL) - error(103); /* insufficient memory (fatal error) */ + error(303); /* insufficient memory (fatal error) */ return cur; } @@ -277,7 +277,7 @@ SC_FUNC stringpair *insert_subst(char *pattern,char *substitution,int prefixlen) assert(pattern!=NULL); assert(substitution!=NULL); if ((cur=insert_stringpair(&substpair,pattern,substitution,prefixlen))==NULL) - error(103); /* insufficient memory (fatal error) */ + error(303); /* insufficient memory (fatal error) */ adjustindex(*pattern); return cur; } @@ -396,7 +396,7 @@ SC_FUNC valuepair *push_heaplist(long first, long second) { valuepair *cur, *last; if ((cur=malloc(sizeof(valuepair)))==NULL) - error(103); /* insufficient memory (fatal error) */ + error(303); /* insufficient memory (fatal error) */ cur->first=first; cur->second=second; diff --git a/source/compiler/scstate.c b/source/compiler/scstate.c index cff98e15..efd9993a 100644 --- a/source/compiler/scstate.c +++ b/source/compiler/scstate.c @@ -183,7 +183,7 @@ SC_FUNC void state_buildlist(int **list,int *listsize,int *count,int stateid) *listsize+=4; newlist=(int*)realloc(*list,*listsize*sizeof(int)); if (newlist==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ *list=newlist; } /* if */ @@ -240,10 +240,10 @@ SC_FUNC int state_addlist(int *list,int count,int fsa) ptr=state_findlist(list,count,fsa,&last); if (ptr==NULL) { if ((ptr=(statelist*)malloc(sizeof(statelist)))==NULL) - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ if ((ptr->states=(int*)malloc(count*sizeof(int)))==NULL) { free(ptr); - error(103); /* insufficient memory */ + error(303); /* insufficient memory */ } /* if */ memcpy(ptr->states,list,count*sizeof(int)); ptr->numstates=count; From 1408bbe46a99b6e40ece53a42dd8bdda996256e5 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sat, 15 May 2021 19:05:14 +0700 Subject: [PATCH 2/2] Update tests --- source/compiler/tests/__static_assert.meta | 2 +- source/compiler/tests/gh_542.meta | 2 +- source/compiler/tests/md_array_crash_gh_220.meta | 2 +- source/compiler/tests/raw_error.meta | 2 +- source/compiler/tests/too_many_args_crash_gh_298.meta | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/compiler/tests/__static_assert.meta b/source/compiler/tests/__static_assert.meta index 32252071..d9e1918b 100644 --- a/source/compiler/tests/__static_assert.meta +++ b/source/compiler/tests/__static_assert.meta @@ -18,7 +18,7 @@ __static_assert.pwn(40) : error 008: must be a constant expression; assumed zero __static_assert.pwn(41) : error 001: expected token: "-string-", but found "-identifier-" __static_assert.pwn(42) : error 001: expected token: "-string-", but found "!" __static_assert.pwn(43) : error 001: expected token: "-string-", but found "!" -__static_assert.pwn(49) : fatal error 110: assertion failed: this is zero +__static_assert.pwn(49) : fatal error 310: assertion failed: this is zero Compilation aborted. """ diff --git a/source/compiler/tests/gh_542.meta b/source/compiler/tests/gh_542.meta index b77c2472..0f157358 100644 --- a/source/compiler/tests/gh_542.meta +++ b/source/compiler/tests/gh_542.meta @@ -1,7 +1,7 @@ { 'test_type': 'output_check', 'errors': """ -gh_542.pwn(2) : fatal error 110: assertion failed: false +gh_542.pwn(2) : fatal error 310: assertion failed: false Compilation aborted. diff --git a/source/compiler/tests/md_array_crash_gh_220.meta b/source/compiler/tests/md_array_crash_gh_220.meta index 065c642c..15dc1edf 100644 --- a/source/compiler/tests/md_array_crash_gh_220.meta +++ b/source/compiler/tests/md_array_crash_gh_220.meta @@ -1,7 +1,7 @@ { 'test_type': 'output_check', 'errors': """ -md_array_crash_gh_220.pwn(6) : fatal error 111: user error: OK +md_array_crash_gh_220.pwn(6) : fatal error 311: user error: OK Compilation aborted. """ diff --git a/source/compiler/tests/raw_error.meta b/source/compiler/tests/raw_error.meta index daa48541..d6c97ff3 100644 --- a/source/compiler/tests/raw_error.meta +++ b/source/compiler/tests/raw_error.meta @@ -1,7 +1,7 @@ { 'test_type': 'output_check', 'errors': """ -raw_error.pwn(1) : fatal error 111: user error: "raw error\\" +raw_error.pwn(1) : fatal error 311: user error: "raw error\\" Compilation aborted. """ diff --git a/source/compiler/tests/too_many_args_crash_gh_298.meta b/source/compiler/tests/too_many_args_crash_gh_298.meta index 90170753..c0f03026 100644 --- a/source/compiler/tests/too_many_args_crash_gh_298.meta +++ b/source/compiler/tests/too_many_args_crash_gh_298.meta @@ -5,7 +5,7 @@ too_many_args_crash_gh_298.pwn(2) : error 045: too many function arguments too_many_args_crash_gh_298.pwn(2) : warning 215: expression has no effect too_many_args_crash_gh_298.pwn(2) : error 001: expected token: ";", but found ")" too_many_args_crash_gh_298.pwn(2) : error 029: invalid expression, assumed zero -too_many_args_crash_gh_298.pwn(2) : fatal error 107: too many error messages on one line +too_many_args_crash_gh_298.pwn(2) : fatal error 307: too many error messages on one line Compilation aborted. """