Misc. minor fixes (#423)
* Misc. minor fixes * Fix OOB array access in encode_cell() * Fix memory leaks in plungequalifiedfile() * Remove redundant NULL pointer checks * Fix invalid uses of realloc() * Remove 'do_switch()' * Don't use 'strlen()' to identify empty strings * Other minor fixes * Fix incorrect error message when compression is ineffective * Add macro 'strempty' to identify empty strings
This commit is contained in:
parent
e645ffceef
commit
0cb9fb3ff6
@ -90,14 +90,11 @@ int memfile_write(memfile_t *mf, const void *buffer, size_t size)
|
|||||||
assert(buffer != NULL);
|
assert(buffer != NULL);
|
||||||
if (mf->offs + size > mf->size)
|
if (mf->offs + size > mf->size)
|
||||||
{
|
{
|
||||||
char *orgbase = mf->base; /* save, in case realloc() fails */
|
|
||||||
size_t newsize = (mf->size + size) * 2;
|
size_t newsize = (mf->size + size) * 2;
|
||||||
mf->base = (char *)realloc(mf->base, newsize);
|
char *newbase = (char *)realloc(mf->base, newsize);
|
||||||
if (!mf->base)
|
if (!newbase)
|
||||||
{
|
|
||||||
mf->base = orgbase; /* restore old pointer to avoid a memory leak */
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
mf->base = newbase;
|
||||||
mf->size = newsize;
|
mf->size = newsize;
|
||||||
}
|
}
|
||||||
memcpy(mf->base + mf->offs, buffer, size);
|
memcpy(mf->base + mf->offs, buffer, size);
|
||||||
|
@ -59,6 +59,10 @@
|
|||||||
#define SC_FASTCALL
|
#define SC_FASTCALL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined strempty
|
||||||
|
#define strempty(str) ((str)[0]=='\0')
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Note: the "cell" and "ucell" types are defined in AMX.H */
|
/* Note: the "cell" and "ucell" types are defined in AMX.H */
|
||||||
|
|
||||||
#define PUBLIC_CHAR '@' /* character that defines a function "public" */
|
#define PUBLIC_CHAR '@' /* character that defines a function "public" */
|
||||||
|
@ -509,7 +509,7 @@ int pc_compile(int argc, char *argv[])
|
|||||||
set_extension(outfname,".lst",TRUE);
|
set_extension(outfname,".lst",TRUE);
|
||||||
else
|
else
|
||||||
set_extension(outfname,".asm",TRUE);
|
set_extension(outfname,".asm",TRUE);
|
||||||
if (strlen(errfname)!=0)
|
if (!strempty(errfname))
|
||||||
remove(errfname); /* delete file on startup */
|
remove(errfname); /* delete file on startup */
|
||||||
else if (verbosity>0)
|
else if (verbosity>0)
|
||||||
setcaption();
|
setcaption();
|
||||||
@ -600,7 +600,7 @@ int pc_compile(int argc, char *argv[])
|
|||||||
sc_status=statFIRST; /* resetglobals() resets it to IDLE */
|
sc_status=statFIRST; /* resetglobals() resets it to IDLE */
|
||||||
setstringconstants();
|
setstringconstants();
|
||||||
setfileconst(inpfname);
|
setfileconst(inpfname);
|
||||||
if (strlen(incfname)>0) {
|
if (!strempty(incfname)) {
|
||||||
if (strcmp(incfname,sDEF_PREFIX)==0) {
|
if (strcmp(incfname,sDEF_PREFIX)==0) {
|
||||||
plungefile(incfname,FALSE,TRUE); /* parse "default.inc" */
|
plungefile(incfname,FALSE,TRUE); /* parse "default.inc" */
|
||||||
} else {
|
} else {
|
||||||
@ -624,11 +624,11 @@ int pc_compile(int argc, char *argv[])
|
|||||||
#if !defined SC_LIGHT
|
#if !defined SC_LIGHT
|
||||||
if (sc_makereport) {
|
if (sc_makereport) {
|
||||||
FILE *frep=stdout;
|
FILE *frep=stdout;
|
||||||
if (strlen(reportname)>0)
|
if (!strempty(reportname))
|
||||||
frep=fopen(reportname,"wb"); /* avoid translation of \n to \r\n in DOS/Windows */
|
frep=fopen(reportname,"wb"); /* avoid translation of \n to \r\n in DOS/Windows */
|
||||||
if (frep!=NULL) {
|
if (frep!=NULL) {
|
||||||
make_report(&glbtab,frep,get_sourcefile(0));
|
make_report(&glbtab,frep,get_sourcefile(0));
|
||||||
if (strlen(reportname)>0)
|
if (!strempty(reportname))
|
||||||
fclose(frep);
|
fclose(frep);
|
||||||
} /* if */
|
} /* if */
|
||||||
if (sc_documentation!=NULL) {
|
if (sc_documentation!=NULL) {
|
||||||
@ -689,7 +689,7 @@ int pc_compile(int argc, char *argv[])
|
|||||||
writeleader(&glbtab);
|
writeleader(&glbtab);
|
||||||
setfileconst(inpfname);
|
setfileconst(inpfname);
|
||||||
insert_dbgfile(inpfname);
|
insert_dbgfile(inpfname);
|
||||||
if (strlen(incfname)>0) {
|
if (!strempty(incfname)) {
|
||||||
if (strcmp(incfname,sDEF_PREFIX)==0)
|
if (strcmp(incfname,sDEF_PREFIX)==0)
|
||||||
plungefile(incfname,FALSE,TRUE); /* parse "default.inc" (again) */
|
plungefile(incfname,FALSE,TRUE); /* parse "default.inc" (again) */
|
||||||
else
|
else
|
||||||
@ -731,7 +731,7 @@ cleanup:
|
|||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
#if !defined SC_LIGHT
|
#if !defined SC_LIGHT
|
||||||
if (errnum==0 && strlen(errfname)==0) {
|
if (errnum==0 && strempty(errfname)) {
|
||||||
int recursion;
|
int recursion;
|
||||||
long stacksize=max_stacksize(&glbtab,&recursion);
|
long stacksize=max_stacksize(&glbtab,&recursion);
|
||||||
int flag_exceed=0;
|
int flag_exceed=0;
|
||||||
@ -767,10 +767,8 @@ cleanup:
|
|||||||
remove(tname); /* the "input file" was in fact a temporary file */
|
remove(tname); /* the "input file" was in fact a temporary file */
|
||||||
free(tname);
|
free(tname);
|
||||||
} /* if */
|
} /* if */
|
||||||
if (inpfname!=NULL)
|
free(inpfname);
|
||||||
free(inpfname);
|
free(litq);
|
||||||
if (litq!=NULL)
|
|
||||||
free(litq);
|
|
||||||
stgbuffer_cleanup();
|
stgbuffer_cleanup();
|
||||||
clearstk();
|
clearstk();
|
||||||
assert(jmpcode!=0 || loctab.next==NULL);/* on normal flow, local symbols
|
assert(jmpcode!=0 || loctab.next==NULL);/* on normal flow, local symbols
|
||||||
@ -794,17 +792,16 @@ cleanup:
|
|||||||
#endif
|
#endif
|
||||||
#if !defined SC_LIGHT
|
#if !defined SC_LIGHT
|
||||||
delete_docstringtable();
|
delete_docstringtable();
|
||||||
if (sc_documentation!=NULL)
|
free(sc_documentation);
|
||||||
free(sc_documentation);
|
|
||||||
#endif
|
#endif
|
||||||
delete_autolisttable();
|
delete_autolisttable();
|
||||||
delete_heaplisttable();
|
delete_heaplisttable();
|
||||||
if (errnum!=0) {
|
if (errnum!=0) {
|
||||||
if (strlen(errfname)==0)
|
if (strempty(errfname))
|
||||||
pc_printf("\n%d Error%s.\n",errnum,(errnum>1) ? "s" : "");
|
pc_printf("\n%d Error%s.\n",errnum,(errnum>1) ? "s" : "");
|
||||||
retcode=1;
|
retcode=1;
|
||||||
} else if (warnnum!=0){
|
} else if (warnnum!=0){
|
||||||
if (strlen(errfname)==0)
|
if (strempty(errfname))
|
||||||
pc_printf("\n%d Warning%s.\n",warnnum,(warnnum>1) ? "s" : "");
|
pc_printf("\n%d Warning%s.\n",warnnum,(warnnum>1) ? "s" : "");
|
||||||
retcode=0; /* use "0", so that MAKE and similar tools continue */
|
retcode=0; /* use "0", so that MAKE and similar tools continue */
|
||||||
} else {
|
} else {
|
||||||
@ -1152,10 +1149,10 @@ static void parseoptions(int argc,char **argv,char *oname,char *ename,char *pnam
|
|||||||
break;
|
break;
|
||||||
strlcpy(rname,option_value(ptr),_MAX_PATH); /* set name of report file */
|
strlcpy(rname,option_value(ptr),_MAX_PATH); /* set name of report file */
|
||||||
sc_makereport=TRUE;
|
sc_makereport=TRUE;
|
||||||
if (strlen(rname)>0) {
|
if (!strempty(rname)) {
|
||||||
set_extension(rname,".xml",FALSE);
|
set_extension(rname,".xml",FALSE);
|
||||||
} else if ((name=get_sourcefile(0))!=NULL) {
|
} else if ((name=get_sourcefile(0))!=NULL) {
|
||||||
assert(strlen(rname)==0);
|
assert(strempty(rname));
|
||||||
assert(strlen(name)<_MAX_PATH);
|
assert(strlen(name)<_MAX_PATH);
|
||||||
if ((ptr=strrchr(name,DIRSEP_CHAR))!=NULL)
|
if ((ptr=strrchr(name,DIRSEP_CHAR))!=NULL)
|
||||||
ptr++; /* strip path */
|
ptr++; /* strip path */
|
||||||
@ -1271,7 +1268,7 @@ static void parseoptions(int argc,char **argv,char *oname,char *ename,char *pnam
|
|||||||
/* The output name is the first input name with a different extension,
|
/* The output name is the first input name with a different extension,
|
||||||
* but it is stored in a different directory
|
* but it is stored in a different directory
|
||||||
*/
|
*/
|
||||||
if (strlen(oname)==0) {
|
if (strempty(oname)) {
|
||||||
if ((ptr=strrchr(str,DIRSEP_CHAR))!=NULL)
|
if ((ptr=strrchr(str,DIRSEP_CHAR))!=NULL)
|
||||||
ptr++; /* strip path */
|
ptr++; /* strip path */
|
||||||
else
|
else
|
||||||
@ -1281,7 +1278,7 @@ static void parseoptions(int argc,char **argv,char *oname,char *ename,char *pnam
|
|||||||
} /* if */
|
} /* if */
|
||||||
set_extension(oname,".asm",TRUE);
|
set_extension(oname,".asm",TRUE);
|
||||||
#if !defined SC_LIGHT
|
#if !defined SC_LIGHT
|
||||||
if (sc_makereport && strlen(rname)==0) {
|
if (sc_makereport && strempty(rname)) {
|
||||||
if ((ptr=strrchr(str,DIRSEP_CHAR))!=NULL)
|
if ((ptr=strrchr(str,DIRSEP_CHAR))!=NULL)
|
||||||
ptr++; /* strip path */
|
ptr++; /* strip path */
|
||||||
else
|
else
|
||||||
@ -1452,13 +1449,15 @@ static void setconfig(char *root)
|
|||||||
insert_path(path);
|
insert_path(path);
|
||||||
/* same for the codepage root */
|
/* same for the codepage root */
|
||||||
#if !defined NO_CODEPAGE
|
#if !defined NO_CODEPAGE
|
||||||
*ptr='\0';
|
if (ptr!=NULL)
|
||||||
|
*ptr='\0';
|
||||||
if (!cp_path(path,"codepage"))
|
if (!cp_path(path,"codepage"))
|
||||||
error(109,path); /* codepage path */
|
error(109,path); /* codepage path */
|
||||||
#endif
|
#endif
|
||||||
/* also copy the root path (for the XML documentation) */
|
/* also copy the root path (for the XML documentation) */
|
||||||
#if !defined SC_LIGHT
|
#if !defined SC_LIGHT
|
||||||
*ptr='\0';
|
if (ptr!=NULL)
|
||||||
|
*ptr='\0';
|
||||||
strcpy(sc_rootpath,path);
|
strcpy(sc_rootpath,path);
|
||||||
#endif
|
#endif
|
||||||
} /* if */
|
} /* if */
|
||||||
@ -1472,7 +1471,7 @@ static void setcaption(void)
|
|||||||
|
|
||||||
static void about(void)
|
static void about(void)
|
||||||
{
|
{
|
||||||
if (strlen(errfname)==0) {
|
if (strempty(errfname)) {
|
||||||
setcaption();
|
setcaption();
|
||||||
pc_printf("Usage: pawncc <filename> [filename...] [options]\n\n");
|
pc_printf("Usage: pawncc <filename> [filename...] [options]\n\n");
|
||||||
pc_printf("Options:\n");
|
pc_printf("Options:\n");
|
||||||
@ -1921,8 +1920,7 @@ void sc_attachdocumentation(symbol *sym)
|
|||||||
assert(sym->documentation==NULL);
|
assert(sym->documentation==NULL);
|
||||||
sym->documentation=doc;
|
sym->documentation=doc;
|
||||||
} else {
|
} else {
|
||||||
if (sc_documentation!=NULL)
|
free(sc_documentation);
|
||||||
free(sc_documentation);
|
|
||||||
sc_documentation=doc;
|
sc_documentation=doc;
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
@ -2942,7 +2940,7 @@ static void decl_enum(int vclass,int fstatic)
|
|||||||
needtoken(')');
|
needtoken(')');
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
if (strlen(enumname)>0) {
|
if (!strempty(enumname)) {
|
||||||
/* already create the root symbol, so the fields can have it as their "parent" */
|
/* already create the root symbol, so the fields can have it as their "parent" */
|
||||||
enumsym=add_constant(enumname,0,vclass,tag);
|
enumsym=add_constant(enumname,0,vclass,tag);
|
||||||
if (enumsym!=NULL) {
|
if (enumsym!=NULL) {
|
||||||
@ -3086,8 +3084,7 @@ static int getstates(const char *funcname)
|
|||||||
/* error is already given */
|
/* error is already given */
|
||||||
state_id=0;
|
state_id=0;
|
||||||
} /* if */
|
} /* if */
|
||||||
if (list!=NULL)
|
free(list);
|
||||||
free(list);
|
|
||||||
|
|
||||||
return state_id;
|
return state_id;
|
||||||
}
|
}
|
||||||
@ -3313,7 +3310,7 @@ static int operatoradjust(int opertok,symbol *sym,char *opername,int resulttag)
|
|||||||
error(64); /* cannot change predefined operators */
|
error(64); /* cannot change predefined operators */
|
||||||
|
|
||||||
/* change the operator name */
|
/* change the operator name */
|
||||||
assert(strlen(opername)>0);
|
assert(!strempty(opername));
|
||||||
operator_symname(tmpname,opername,tags[0],tags[1],count,resulttag);
|
operator_symname(tmpname,opername,tags[0],tags[1],count,resulttag);
|
||||||
if ((oldsym=findglb(tmpname,sGLOBAL))!=NULL) {
|
if ((oldsym=findglb(tmpname,sGLOBAL))!=NULL) {
|
||||||
int i;
|
int i;
|
||||||
@ -3339,7 +3336,7 @@ static int operatoradjust(int opertok,symbol *sym,char *opername,int resulttag)
|
|||||||
|
|
||||||
static int check_operatortag(int opertok,int resulttag,char *opername)
|
static int check_operatortag(int opertok,int resulttag,char *opername)
|
||||||
{
|
{
|
||||||
assert(opername!=NULL && strlen(opername)>0);
|
assert(opername!=NULL && !strempty(opername));
|
||||||
switch (opertok) {
|
switch (opertok) {
|
||||||
case '!':
|
case '!':
|
||||||
case '<':
|
case '<':
|
||||||
@ -3614,7 +3611,7 @@ static void funcstub(int fnative)
|
|||||||
if (sym==NULL)
|
if (sym==NULL)
|
||||||
return;
|
return;
|
||||||
if (fnative) {
|
if (fnative) {
|
||||||
sym->usage=(char)(uNATIVE | uRETVALUE | uDEFINE | (sym->usage & uPROTOTYPED));
|
sym->usage=(short)(uNATIVE | uRETVALUE | uDEFINE | (sym->usage & uPROTOTYPED));
|
||||||
sym->x.lib=curlibrary;
|
sym->x.lib=curlibrary;
|
||||||
} else if (fpublic) {
|
} else if (fpublic) {
|
||||||
sym->usage|=uPUBLIC;
|
sym->usage|=uPUBLIC;
|
||||||
@ -3802,7 +3799,7 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc
|
|||||||
if (state_id!=0) {
|
if (state_id!=0) {
|
||||||
constvalue *ptr=sym->states->first;
|
constvalue *ptr=sym->states->first;
|
||||||
while (ptr!=NULL) {
|
while (ptr!=NULL) {
|
||||||
assert(sc_status!=statWRITE || strlen(ptr->name)>0);
|
assert(sc_status!=statWRITE || !strempty(ptr->name));
|
||||||
if (ptr->index==state_id) {
|
if (ptr->index==state_id) {
|
||||||
setlabel((int)strtol(ptr->name,NULL,16));
|
setlabel((int)strtol(ptr->name,NULL,16));
|
||||||
break;
|
break;
|
||||||
@ -4016,9 +4013,10 @@ static int declargs(symbol *sym,int chkshadow)
|
|||||||
error(59,name); /* arguments of a public function may not have a default value */
|
error(59,name); /* arguments of a public function may not have a default value */
|
||||||
if ((sym->usage & uPROTOTYPED)==0) {
|
if ((sym->usage & uPROTOTYPED)==0) {
|
||||||
/* redimension the argument list, add the entry */
|
/* redimension the argument list, add the entry */
|
||||||
sym->dim.arglist=(arginfo*)realloc(sym->dim.arglist,(argcnt+2)*sizeof(arginfo));
|
arginfo* new_arglist=(arginfo*)realloc(sym->dim.arglist,(argcnt+2)*sizeof(arginfo));
|
||||||
if (sym->dim.arglist==0)
|
if (new_arglist==NULL)
|
||||||
error(103); /* insufficient memory */
|
error(103); /* insufficient memory */
|
||||||
|
sym->dim.arglist=new_arglist;
|
||||||
memset(&sym->dim.arglist[argcnt+1],0,sizeof(arginfo)); /* keep the list terminated */
|
memset(&sym->dim.arglist[argcnt+1],0,sizeof(arginfo)); /* keep the list terminated */
|
||||||
sym->dim.arglist[argcnt]=arg;
|
sym->dim.arglist[argcnt]=arg;
|
||||||
} else {
|
} else {
|
||||||
@ -4047,9 +4045,10 @@ static int declargs(symbol *sym,int chkshadow)
|
|||||||
tags[numtags++]=0; /* default tag */
|
tags[numtags++]=0; /* default tag */
|
||||||
if ((sym->usage & uPROTOTYPED)==0) {
|
if ((sym->usage & uPROTOTYPED)==0) {
|
||||||
/* redimension the argument list, add the entry iVARARGS */
|
/* redimension the argument list, add the entry iVARARGS */
|
||||||
sym->dim.arglist=(arginfo*)realloc(sym->dim.arglist,(argcnt+2)*sizeof(arginfo));
|
arginfo* new_arglist=(arginfo*)realloc(sym->dim.arglist,(argcnt+2)*sizeof(arginfo));
|
||||||
if (sym->dim.arglist==0)
|
if (new_arglist==NULL)
|
||||||
error(103); /* insufficient memory */
|
error(103); /* insufficient memory */
|
||||||
|
sym->dim.arglist=new_arglist;
|
||||||
memset(&sym->dim.arglist[argcnt+1],0,sizeof(arginfo)); /* keep the list terminated */
|
memset(&sym->dim.arglist[argcnt+1],0,sizeof(arginfo)); /* keep the list terminated */
|
||||||
sym->dim.arglist[argcnt].ident=iVARARGS;
|
sym->dim.arglist[argcnt].ident=iVARARGS;
|
||||||
sym->dim.arglist[argcnt].hasdefault=FALSE;
|
sym->dim.arglist[argcnt].hasdefault=FALSE;
|
||||||
@ -4586,7 +4585,7 @@ static void make_report(symbol *root,FILE *log,char *sourcefile)
|
|||||||
assert(i>=0); /* automaton 0 exists */
|
assert(i>=0); /* automaton 0 exists */
|
||||||
stlist=automaton_findid(i);
|
stlist=automaton_findid(i);
|
||||||
assert(stlist!=NULL); /* automaton should be found */
|
assert(stlist!=NULL); /* automaton should be found */
|
||||||
fprintf(log,"\t\t\t<automaton name=\"%s\"/>\n", strlen(stlist->name)>0 ? stlist->name : "(anonymous)");
|
fprintf(log,"\t\t\t<automaton name=\"%s\"/>\n", !strempty(stlist->name) ? stlist->name : "(anonymous)");
|
||||||
//??? dump state decision table
|
//??? dump state decision table
|
||||||
} /* if */
|
} /* if */
|
||||||
assert(sym->refer!=NULL);
|
assert(sym->refer!=NULL);
|
||||||
@ -4890,7 +4889,7 @@ static int testsymbols(symbol *root,int level,int testlabs,int testconst)
|
|||||||
case iFUNCTN:
|
case iFUNCTN:
|
||||||
if ((sym->usage & (uDEFINE | uREAD | uNATIVE | uSTOCK | uPUBLIC))==uDEFINE) {
|
if ((sym->usage & (uDEFINE | uREAD | uNATIVE | uSTOCK | uPUBLIC))==uDEFINE) {
|
||||||
funcdisplayname(symname,sym->name);
|
funcdisplayname(symname,sym->name);
|
||||||
if (strlen(symname)>0)
|
if (!strempty(symname))
|
||||||
error(203,symname); /* symbol isn't used ... (and not public/native/stock) */
|
error(203,symname); /* symbol isn't used ... (and not public/native/stock) */
|
||||||
} /* if */
|
} /* if */
|
||||||
if ((sym->usage & uPUBLIC)!=0 || strcmp(sym->name,uMAINFUNC)==0)
|
if ((sym->usage & uPUBLIC)!=0 || strcmp(sym->name,uMAINFUNC)==0)
|
||||||
@ -7535,6 +7534,7 @@ static void doreturn(void)
|
|||||||
ident=doexpr(TRUE,FALSE,TRUE,FALSE,&tag,&sym,TRUE);
|
ident=doexpr(TRUE,FALSE,TRUE,FALSE,&tag,&sym,TRUE);
|
||||||
needtoken(tTERM);
|
needtoken(tTERM);
|
||||||
/* see if this function already has a sub type (an array attached) */
|
/* see if this function already has a sub type (an array attached) */
|
||||||
|
assert(curfunc!=NULL);
|
||||||
sub=finddepend(curfunc);
|
sub=finddepend(curfunc);
|
||||||
assert(sub==NULL || sub->ident==iREFARRAY);
|
assert(sub==NULL || sub->ident==iREFARRAY);
|
||||||
if ((rettype & uRETVALUE)!=0) {
|
if ((rettype & uRETVALUE)!=0) {
|
||||||
@ -7547,7 +7547,6 @@ static void doreturn(void)
|
|||||||
} /* if */
|
} /* if */
|
||||||
rettype|=uRETVALUE; /* function returns a value */
|
rettype|=uRETVALUE; /* function returns a value */
|
||||||
/* check tagname with function tagname */
|
/* check tagname with function tagname */
|
||||||
assert(curfunc!=NULL);
|
|
||||||
check_tagmismatch(curfunc->tag,tag,TRUE,-1);
|
check_tagmismatch(curfunc->tag,tag,TRUE,-1);
|
||||||
if (ident==iARRAY || ident==iREFARRAY) {
|
if (ident==iARRAY || ident==iREFARRAY) {
|
||||||
int dim[sDIMEN_MAX],numdim=0;
|
int dim[sDIMEN_MAX],numdim=0;
|
||||||
@ -7617,8 +7616,7 @@ static void doreturn(void)
|
|||||||
sub=addvariable(curfunc->name,(argcount+3)*sizeof(cell),iREFARRAY,sGLOBAL,
|
sub=addvariable(curfunc->name,(argcount+3)*sizeof(cell),iREFARRAY,sGLOBAL,
|
||||||
curfunc->tag,dim,numdim,idxtag,0);
|
curfunc->tag,dim,numdim,idxtag,0);
|
||||||
sub->parent=curfunc;
|
sub->parent=curfunc;
|
||||||
if (curfunc)
|
curfunc->child=sub;
|
||||||
curfunc->child=sub;
|
|
||||||
} /* if */
|
} /* if */
|
||||||
/* get the hidden parameter, copy the array (the array is on the heap;
|
/* get the hidden parameter, copy the array (the array is on the heap;
|
||||||
* it stays on the heap for the moment, and it is removed -usually- at
|
* it stays on the heap for the moment, and it is removed -usually- at
|
||||||
@ -7774,7 +7772,7 @@ static void dostate(void)
|
|||||||
sym=findglb(uENTRYFUNC,sGLOBAL);
|
sym=findglb(uENTRYFUNC,sGLOBAL);
|
||||||
if (sc_status==statWRITE && sym!=NULL && sym->ident==iFUNCTN && sym->states!=NULL) {
|
if (sc_status==statWRITE && sym!=NULL && sym->ident==iFUNCTN && sym->states!=NULL) {
|
||||||
for (stlist=sym->states->first; stlist!=NULL; stlist=stlist->next) {
|
for (stlist=sym->states->first; stlist!=NULL; stlist=stlist->next) {
|
||||||
assert(strlen(stlist->name)!=0);
|
assert(!strempty(stlist->name));
|
||||||
if (state_getfsa(stlist->index)==automaton->index && state_inlist(stlist->index,(int)state->value))
|
if (state_getfsa(stlist->index)==automaton->index && state_inlist(stlist->index,(int)state->value))
|
||||||
break; /* found! */
|
break; /* found! */
|
||||||
} /* for */
|
} /* for */
|
||||||
|
@ -92,13 +92,9 @@ SC_FUNC void pushstk(stkitem val)
|
|||||||
int newsize= (stktop==0) ? 16 : 2*stktop;
|
int newsize= (stktop==0) ? 16 : 2*stktop;
|
||||||
/* try to resize the stack */
|
/* try to resize the stack */
|
||||||
assert(newsize>stktop);
|
assert(newsize>stktop);
|
||||||
newstack=(stkitem*)malloc(newsize*sizeof(stkitem));
|
newstack=(stkitem*)realloc(stack,newsize*sizeof(stkitem));
|
||||||
if (newstack==NULL)
|
if (newstack==NULL)
|
||||||
error(102,"parser stack"); /* stack overflow (recursive include?) */
|
error(102,"parser stack"); /* stack overflow (recursive include?) */
|
||||||
/* swap the stacks */
|
|
||||||
memcpy(newstack,stack,stkidx*sizeof(stkitem));
|
|
||||||
if (stack!=NULL)
|
|
||||||
free(stack);
|
|
||||||
stack=newstack;
|
stack=newstack;
|
||||||
stktop=newsize;
|
stktop=newsize;
|
||||||
} /* if */
|
} /* if */
|
||||||
@ -148,8 +144,10 @@ static char extensions[][6] = { "", ".inc", ".p", ".pawn" };
|
|||||||
error(103); /* insufficient memory */
|
error(103); /* insufficient memory */
|
||||||
strcpy(path,name);
|
strcpy(path,name);
|
||||||
real_path=(char *)malloc(strlen(name)+sizeof(extensions[0]));
|
real_path=(char *)malloc(strlen(name)+sizeof(extensions[0]));
|
||||||
if (real_path==NULL)
|
if (real_path==NULL) {
|
||||||
|
free(path);
|
||||||
error(103); /* insufficient memory */
|
error(103); /* insufficient memory */
|
||||||
|
} /* if */
|
||||||
do {
|
do {
|
||||||
found=TRUE;
|
found=TRUE;
|
||||||
ext=strchr(path,'\0'); /* save position */
|
ext=strchr(path,'\0'); /* save position */
|
||||||
@ -172,11 +170,13 @@ static char extensions[][6] = { "", ".inc", ".p", ".pawn" };
|
|||||||
if (fp==NULL) {
|
if (fp==NULL) {
|
||||||
*ext='\0'; /* on failure, restore filename */
|
*ext='\0'; /* on failure, restore filename */
|
||||||
found=FALSE;
|
found=FALSE;
|
||||||
}
|
} /* if */
|
||||||
ext_idx++;
|
ext_idx++;
|
||||||
} while (!found && ext_idx<(sizeof extensions / sizeof extensions[0]));
|
} while (!found && ext_idx<(sizeof extensions / sizeof extensions[0]));
|
||||||
if (!found) {
|
if (!found) {
|
||||||
*ext='\0'; /* restore filename */
|
*ext='\0'; /* restore filename */
|
||||||
|
free(path);
|
||||||
|
free(real_path);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} /* if */
|
} /* if */
|
||||||
PUSHSTK_P(inpf);
|
PUSHSTK_P(inpf);
|
||||||
@ -469,7 +469,7 @@ static void stripcomment(unsigned char *line)
|
|||||||
if (icomment==2) {
|
if (icomment==2) {
|
||||||
assert(commentidx<COMMENT_LIMIT+COMMENT_MARGIN);
|
assert(commentidx<COMMENT_LIMIT+COMMENT_MARGIN);
|
||||||
comment[commentidx]='\0';
|
comment[commentidx]='\0';
|
||||||
if (strlen(comment)>0)
|
if (!strempty(comment))
|
||||||
insert_docstring(comment);
|
insert_docstring(comment);
|
||||||
} /* if */
|
} /* if */
|
||||||
#endif
|
#endif
|
||||||
@ -576,7 +576,7 @@ static void stripcomment(unsigned char *line)
|
|||||||
if (icomment==2) {
|
if (icomment==2) {
|
||||||
assert(commentidx<COMMENT_LIMIT+COMMENT_MARGIN);
|
assert(commentidx<COMMENT_LIMIT+COMMENT_MARGIN);
|
||||||
comment[commentidx]='\0';
|
comment[commentidx]='\0';
|
||||||
if (strlen(comment)>0)
|
if (!strempty(comment))
|
||||||
insert_docstring(comment);
|
insert_docstring(comment);
|
||||||
} /* if */
|
} /* if */
|
||||||
#endif
|
#endif
|
||||||
@ -1092,7 +1092,7 @@ static int command(void)
|
|||||||
if (!SKIPPING) {
|
if (!SKIPPING) {
|
||||||
char pathname[_MAX_PATH];
|
char pathname[_MAX_PATH];
|
||||||
lptr=getstring((unsigned char*)pathname,sizeof pathname,lptr);
|
lptr=getstring((unsigned char*)pathname,sizeof pathname,lptr);
|
||||||
if (strlen(pathname)>0) {
|
if (!strempty(pathname)) {
|
||||||
free(inpfname);
|
free(inpfname);
|
||||||
inpfname=duplicatestring(pathname);
|
inpfname=duplicatestring(pathname);
|
||||||
if (inpfname==NULL)
|
if (inpfname==NULL)
|
||||||
@ -1183,7 +1183,7 @@ static int command(void)
|
|||||||
name[i]=*lptr;
|
name[i]=*lptr;
|
||||||
name[i]='\0';
|
name[i]='\0';
|
||||||
} /* if */
|
} /* if */
|
||||||
if (strlen(name)==0) {
|
if (strempty(name)) {
|
||||||
curlibrary=NULL;
|
curlibrary=NULL;
|
||||||
} else if (strcmp(name,"-")==0) {
|
} else if (strcmp(name,"-")==0) {
|
||||||
pc_addlibtable=FALSE;
|
pc_addlibtable=FALSE;
|
||||||
@ -1508,7 +1508,7 @@ static int command(void)
|
|||||||
delete_subst(pattern,prefixlen);
|
delete_subst(pattern,prefixlen);
|
||||||
} /* if */
|
} /* if */
|
||||||
/* add the pattern/substitution pair to the list */
|
/* add the pattern/substitution pair to the list */
|
||||||
assert(strlen(pattern)>0);
|
assert(!strempty(pattern));
|
||||||
insert_subst(pattern,substitution,prefixlen);
|
insert_subst(pattern,substitution,prefixlen);
|
||||||
free(pattern);
|
free(pattern);
|
||||||
free(substitution);
|
free(substitution);
|
||||||
@ -1712,8 +1712,7 @@ static int substpattern(unsigned char *line,size_t buffersize,char *pattern,char
|
|||||||
* a string, or the closing paranthese of a group) */
|
* a string, or the closing paranthese of a group) */
|
||||||
} /* while */
|
} /* while */
|
||||||
/* store the parameter (overrule any earlier) */
|
/* store the parameter (overrule any earlier) */
|
||||||
if (args[arg]!=NULL)
|
free(args[arg]);
|
||||||
free(args[arg]);
|
|
||||||
len=(int)(e-s);
|
len=(int)(e-s);
|
||||||
args[arg]=(unsigned char*)malloc(len+1);
|
args[arg]=(unsigned char*)malloc(len+1);
|
||||||
if (args[arg]==NULL)
|
if (args[arg]==NULL)
|
||||||
@ -1815,8 +1814,7 @@ static int substpattern(unsigned char *line,size_t buffersize,char *pattern,char
|
|||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
for (arg=0; arg<10; arg++)
|
for (arg=0; arg<10; arg++)
|
||||||
if (args[arg]!=NULL)
|
free(args[arg]);
|
||||||
free(args[arg]);
|
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
@ -2905,8 +2903,7 @@ static void free_symbol(symbol *sym)
|
|||||||
} /* if */
|
} /* if */
|
||||||
assert(sym->refer!=NULL);
|
assert(sym->refer!=NULL);
|
||||||
free(sym->refer);
|
free(sym->refer);
|
||||||
if (sym->documentation!=NULL)
|
free(sym->documentation);
|
||||||
free(sym->documentation);
|
|
||||||
if (sym->vclass==sGLOBAL)
|
if (sym->vclass==sGLOBAL)
|
||||||
symbol_cache_remove(sym);
|
symbol_cache_remove(sym);
|
||||||
free(sym);
|
free(sym);
|
||||||
|
@ -1673,7 +1673,7 @@ restart:
|
|||||||
cell2addr(); /* normal array index */
|
cell2addr(); /* normal array index */
|
||||||
} else {
|
} else {
|
||||||
if (sym->dim.array.length!=0)
|
if (sym->dim.array.length!=0)
|
||||||
ffbounds(sym->dim.array.length*(32/sCHARBITS)-1);
|
ffbounds(sym->dim.array.length*((sizeof(cell)*8)/sCHARBITS)-1);
|
||||||
char2addr(); /* character array index */
|
char2addr(); /* character array index */
|
||||||
} /* if */
|
} /* if */
|
||||||
popreg(sALT);
|
popreg(sALT);
|
||||||
|
@ -79,7 +79,7 @@ SC_FUNC void writeleader(symbol *root)
|
|||||||
for (fsa=sc_automaton_tab.first; fsa!=NULL; fsa=fsa->next) {
|
for (fsa=sc_automaton_tab.first; fsa!=NULL; fsa=fsa->next) {
|
||||||
defstorage();
|
defstorage();
|
||||||
stgwrite("0\t; automaton ");
|
stgwrite("0\t; automaton ");
|
||||||
if (strlen(fsa->name)==0)
|
if (strempty(fsa->name))
|
||||||
stgwrite("(anonymous)");
|
stgwrite("(anonymous)");
|
||||||
else
|
else
|
||||||
stgwrite(fsa->name);
|
stgwrite(fsa->name);
|
||||||
@ -111,7 +111,7 @@ SC_FUNC void writeleader(symbol *root)
|
|||||||
} /* if */
|
} /* if */
|
||||||
/* generate label numbers for all statelist ids */
|
/* generate label numbers for all statelist ids */
|
||||||
for (stlist=sym->states->first; stlist!=NULL; stlist=stlist->next) {
|
for (stlist=sym->states->first; stlist!=NULL; stlist=stlist->next) {
|
||||||
assert(strlen(stlist->name)==0);
|
assert(strempty(stlist->name));
|
||||||
strcpy(stlist->name,itoh(getlabel()));
|
strcpy(stlist->name,itoh(getlabel()));
|
||||||
} /* for */
|
} /* for */
|
||||||
if (strcmp(sym->name,uENTRYFUNC)==0)
|
if (strcmp(sym->name,uENTRYFUNC)==0)
|
||||||
|
@ -259,13 +259,15 @@ static unsigned char *encode_cell(ucell c,int *len)
|
|||||||
c>>=7;
|
c>>=7;
|
||||||
} while (index>=0);
|
} while (index>=0);
|
||||||
/* skip leading zeros */
|
/* skip leading zeros */
|
||||||
while (index<ENC_MAX-1 && buffer[index]==0 && (buffer[index+1] & 0x40)==0)
|
while (index<ENC_MAX-2 && buffer[index+1]==0 && (buffer[index+2] & 0x40)==0)
|
||||||
index++;
|
index++;
|
||||||
/* skip leading -1s */
|
/* skip leading -1s */
|
||||||
if (index==0 && buffer[index]==ENC_MASK && (buffer[index+1] & 0x40)!=0)
|
if (index==-1 && buffer[index+1]==ENC_MASK && (buffer[index+2] & 0x40)!=0)
|
||||||
index++;
|
index++;
|
||||||
while (index<ENC_MAX-1 && buffer[index]==0x7f && (buffer[index+1] & 0x40)!=0)
|
while (index<ENC_MAX-2 && buffer[index+1]==0x7f && (buffer[index+2] & 0x40)!=0)
|
||||||
index++;
|
index++;
|
||||||
|
assert(index<ENC_MAX-1);
|
||||||
|
++index;
|
||||||
*len=ENC_MAX-index;
|
*len=ENC_MAX-index;
|
||||||
ptr=&buffer[index];
|
ptr=&buffer[index];
|
||||||
while (index<ENC_MAX-1)
|
while (index<ENC_MAX-1)
|
||||||
@ -286,7 +288,7 @@ static void write_encoded(FILE *fbin,ucell *c,int num)
|
|||||||
writeerror |= !pc_writebin(fbin,bytes,len);
|
writeerror |= !pc_writebin(fbin,bytes,len);
|
||||||
bytes_out+=len;
|
bytes_out+=len;
|
||||||
bytes_in+=sizeof *c;
|
bytes_in+=sizeof *c;
|
||||||
assert(AMX_COMPACTMARGIN>2);
|
assert_static(AMX_COMPACTMARGIN>2);
|
||||||
if (bytes_out-bytes_in>=AMX_COMPACTMARGIN-2)
|
if (bytes_out-bytes_in>=AMX_COMPACTMARGIN-2)
|
||||||
longjmp(compact_err,1);
|
longjmp(compact_err,1);
|
||||||
} else {
|
} else {
|
||||||
@ -308,6 +310,7 @@ static void write_encoded_n(FILE *fbin,ucell c,int num)
|
|||||||
assert(len>0);
|
assert(len>0);
|
||||||
bytes_in += num*sizeof c;
|
bytes_in += num*sizeof c;
|
||||||
bytes_out += num*len;
|
bytes_out += num*len;
|
||||||
|
assert_static(AMX_COMPACTMARGIN>2);
|
||||||
if (bytes_out-bytes_in>=AMX_COMPACTMARGIN-2)
|
if (bytes_out-bytes_in>=AMX_COMPACTMARGIN-2)
|
||||||
longjmp(compact_err,1);
|
longjmp(compact_err,1);
|
||||||
while (num-->0)
|
while (num-->0)
|
||||||
@ -507,23 +510,6 @@ static cell SC_FASTCALL do_jump(FILE *fbin,char *params,cell opcode)
|
|||||||
return opcodes(1)+opargs(1);
|
return opcodes(1)+opargs(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static cell SC_FASTCALL do_switch(FILE *fbin,char *params,cell opcode)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
ucell p;
|
|
||||||
|
|
||||||
i=(int)hex2long(params,NULL);
|
|
||||||
assert(i>=0 && i<sc_labnum);
|
|
||||||
|
|
||||||
if (fbin!=NULL) {
|
|
||||||
assert(lbltab!=NULL);
|
|
||||||
p=lbltab[i];
|
|
||||||
write_encoded(fbin,(ucell*)&opcode,1);
|
|
||||||
write_encoded(fbin,&p,1);
|
|
||||||
} /* if */
|
|
||||||
return opcodes(1)+opargs(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||||
#pragma argsused
|
#pragma argsused
|
||||||
#endif
|
#endif
|
||||||
@ -697,7 +683,7 @@ static OPCODE opcodelist[] = {
|
|||||||
{ 80, "sub.alt", sIN_CSEG, parm0 },
|
{ 80, "sub.alt", sIN_CSEG, parm0 },
|
||||||
{132, "swap.alt", sIN_CSEG, parm0 }, /* version 4 */
|
{132, "swap.alt", sIN_CSEG, parm0 }, /* version 4 */
|
||||||
{131, "swap.pri", sIN_CSEG, parm0 }, /* version 4 */
|
{131, "swap.pri", sIN_CSEG, parm0 }, /* version 4 */
|
||||||
{129, "switch", sIN_CSEG, do_switch }, /* version 1 */
|
{129, "switch", sIN_CSEG, do_jump }, /* version 1 */
|
||||||
/*{126, "symbol", sIN_CSEG, do_symbol }, */
|
/*{126, "symbol", sIN_CSEG, do_symbol }, */
|
||||||
/*{136, "symtag", sIN_CSEG, parm1 }, -- version 7 */
|
/*{136, "symtag", sIN_CSEG, parm1 }, -- version 7 */
|
||||||
{123, "sysreq.c", sIN_CSEG, parm1 },
|
{123, "sysreq.c", sIN_CSEG, parm1 },
|
||||||
@ -822,7 +808,7 @@ SC_FUNC int assemble(FILE *fout,FILE *fin)
|
|||||||
if (pc_addlibtable) {
|
if (pc_addlibtable) {
|
||||||
for (constptr=libname_tab.first; constptr!=NULL; constptr=constptr->next) {
|
for (constptr=libname_tab.first; constptr!=NULL; constptr=constptr->next) {
|
||||||
if (constptr->value>0) {
|
if (constptr->value>0) {
|
||||||
assert(strlen(constptr->name)>0);
|
assert(!strempty(constptr->name));
|
||||||
numlibraries++;
|
numlibraries++;
|
||||||
nametablesize+=strlen(constptr->name)+1;
|
nametablesize+=strlen(constptr->name)+1;
|
||||||
} /* if */
|
} /* if */
|
||||||
@ -833,7 +819,7 @@ SC_FUNC int assemble(FILE *fout,FILE *fin)
|
|||||||
numtags=0;
|
numtags=0;
|
||||||
for (constptr=tagname_tab.first; constptr!=NULL; constptr=constptr->next) {
|
for (constptr=tagname_tab.first; constptr!=NULL; constptr=constptr->next) {
|
||||||
if ((constptr->value & PUBLICTAG)!=0) {
|
if ((constptr->value & PUBLICTAG)!=0) {
|
||||||
assert(strlen(constptr->name)>0);
|
assert(!strempty(constptr->name));
|
||||||
numtags++;
|
numtags++;
|
||||||
nametablesize+=strlen(constptr->name)+1;
|
nametablesize+=strlen(constptr->name)+1;
|
||||||
} /* if */
|
} /* if */
|
||||||
@ -959,7 +945,7 @@ SC_FUNC int assemble(FILE *fout,FILE *fin)
|
|||||||
count=0;
|
count=0;
|
||||||
for (constptr=libname_tab.first; constptr!=NULL; constptr=constptr->next) {
|
for (constptr=libname_tab.first; constptr!=NULL; constptr=constptr->next) {
|
||||||
if (constptr->value>0) {
|
if (constptr->value>0) {
|
||||||
assert(strlen(constptr->name)>0);
|
assert(!strempty(constptr->name));
|
||||||
func.address=0;
|
func.address=0;
|
||||||
func.nameofs=nameofs;
|
func.nameofs=nameofs;
|
||||||
#if BYTE_ORDER==BIG_ENDIAN
|
#if BYTE_ORDER==BIG_ENDIAN
|
||||||
@ -1003,7 +989,7 @@ SC_FUNC int assemble(FILE *fout,FILE *fin)
|
|||||||
count=0;
|
count=0;
|
||||||
for (constptr=tagname_tab.first; constptr!=NULL; constptr=constptr->next) {
|
for (constptr=tagname_tab.first; constptr!=NULL; constptr=constptr->next) {
|
||||||
if ((constptr->value & PUBLICTAG)!=0) {
|
if ((constptr->value & PUBLICTAG)!=0) {
|
||||||
assert(strlen(constptr->name)>0);
|
assert(!strempty(constptr->name));
|
||||||
func.address=constptr->value & TAGMASK;
|
func.address=constptr->value & TAGMASK;
|
||||||
func.nameofs=nameofs;
|
func.nameofs=nameofs;
|
||||||
#if BYTE_ORDER==BIG_ENDIAN
|
#if BYTE_ORDER==BIG_ENDIAN
|
||||||
@ -1097,7 +1083,7 @@ SC_FUNC int assemble(FILE *fout,FILE *fin)
|
|||||||
} /* while */
|
} /* while */
|
||||||
} /* for */
|
} /* for */
|
||||||
if (bytes_out-bytes_in>0)
|
if (bytes_out-bytes_in>0)
|
||||||
error(106); /* compression buffer overflow */
|
longjmp(compact_err,1);
|
||||||
|
|
||||||
if (lbltab!=NULL) {
|
if (lbltab!=NULL) {
|
||||||
free(lbltab);
|
free(lbltab);
|
||||||
@ -1222,21 +1208,21 @@ static void append_dbginfo(FILE *fout)
|
|||||||
|
|
||||||
/* tag table */
|
/* tag table */
|
||||||
for (constptr=tagname_tab.first; constptr!=NULL; constptr=constptr->next) {
|
for (constptr=tagname_tab.first; constptr!=NULL; constptr=constptr->next) {
|
||||||
assert(strlen(constptr->name)>0);
|
assert(!strempty(constptr->name));
|
||||||
dbghdr.tags++;
|
dbghdr.tags++;
|
||||||
dbghdr.size+=sizeof(AMX_DBG_TAG)+strlen(constptr->name);
|
dbghdr.size+=sizeof(AMX_DBG_TAG)+strlen(constptr->name);
|
||||||
} /* for */
|
} /* for */
|
||||||
|
|
||||||
/* automaton table */
|
/* automaton table */
|
||||||
for (constptr=sc_automaton_tab.first; constptr!=NULL; constptr=constptr->next) {
|
for (constptr=sc_automaton_tab.first; constptr!=NULL; constptr=constptr->next) {
|
||||||
assert(constptr->index==0 && strlen(constptr->name)==0 || strlen(constptr->name)>0);
|
assert(constptr->index==0 && strempty(constptr->name) || !strempty(constptr->name));
|
||||||
dbghdr.automatons++;
|
dbghdr.automatons++;
|
||||||
dbghdr.size+=sizeof(AMX_DBG_MACHINE)+strlen(constptr->name);
|
dbghdr.size+=sizeof(AMX_DBG_MACHINE)+strlen(constptr->name);
|
||||||
} /* for */
|
} /* for */
|
||||||
|
|
||||||
/* state table */
|
/* state table */
|
||||||
for (constptr=sc_state_tab.first; constptr!=NULL; constptr=constptr->next) {
|
for (constptr=sc_state_tab.first; constptr!=NULL; constptr=constptr->next) {
|
||||||
assert(strlen(constptr->name)>0);
|
assert(!strempty(constptr->name));
|
||||||
dbghdr.states++;
|
dbghdr.states++;
|
||||||
dbghdr.size+=sizeof(AMX_DBG_STATE)+strlen(constptr->name);
|
dbghdr.size+=sizeof(AMX_DBG_STATE)+strlen(constptr->name);
|
||||||
} /* for */
|
} /* for */
|
||||||
@ -1355,7 +1341,7 @@ static void append_dbginfo(FILE *fout)
|
|||||||
|
|
||||||
/* tag table */
|
/* tag table */
|
||||||
for (constptr=tagname_tab.first; constptr!=NULL; constptr=constptr->next) {
|
for (constptr=tagname_tab.first; constptr!=NULL; constptr=constptr->next) {
|
||||||
assert(strlen(constptr->name)>0);
|
assert(!strempty(constptr->name));
|
||||||
id1=(int16_t)(constptr->value & TAGMASK);
|
id1=(int16_t)(constptr->value & TAGMASK);
|
||||||
#if BYTE_ORDER==BIG_ENDIAN
|
#if BYTE_ORDER==BIG_ENDIAN
|
||||||
align16(&id1);
|
align16(&id1);
|
||||||
@ -1366,7 +1352,7 @@ static void append_dbginfo(FILE *fout)
|
|||||||
|
|
||||||
/* automaton table */
|
/* automaton table */
|
||||||
for (constptr=sc_automaton_tab.first; constptr!=NULL; constptr=constptr->next) {
|
for (constptr=sc_automaton_tab.first; constptr!=NULL; constptr=constptr->next) {
|
||||||
assert(constptr->index==0 && strlen(constptr->name)==0 || strlen(constptr->name)>0);
|
assert(constptr->index==0 && strempty(constptr->name) || !strempty(constptr->name));
|
||||||
id1=(int16_t)constptr->index;
|
id1=(int16_t)constptr->index;
|
||||||
address=(ucell)constptr->value;
|
address=(ucell)constptr->value;
|
||||||
#if BYTE_ORDER==BIG_ENDIAN
|
#if BYTE_ORDER==BIG_ENDIAN
|
||||||
@ -1380,7 +1366,7 @@ static void append_dbginfo(FILE *fout)
|
|||||||
|
|
||||||
/* state table */
|
/* state table */
|
||||||
for (constptr=sc_state_tab.first; constptr!=NULL; constptr=constptr->next) {
|
for (constptr=sc_state_tab.first; constptr!=NULL; constptr=constptr->next) {
|
||||||
assert(strlen(constptr->name)>0);
|
assert(!strempty(constptr->name));
|
||||||
id1=(int16_t)constptr->value;
|
id1=(int16_t)constptr->value;
|
||||||
id2=(int16_t)constptr->index;
|
id2=(int16_t)constptr->index;
|
||||||
address=(ucell)constptr->value;
|
address=(ucell)constptr->value;
|
||||||
|
@ -1276,10 +1276,7 @@ static void grow_stgbuffer(char **buffer, int *curmax, int requiredsize)
|
|||||||
if (requiredsize>sSTG_MAX)
|
if (requiredsize>sSTG_MAX)
|
||||||
error(102,"staging buffer"); /* staging buffer overflow (fatal error) */
|
error(102,"staging buffer"); /* staging buffer overflow (fatal error) */
|
||||||
*curmax=requiredsize+sSTG_GROW;
|
*curmax=requiredsize+sSTG_GROW;
|
||||||
if (*buffer!=NULL)
|
p=(char *)realloc(*buffer,*curmax*sizeof(char));
|
||||||
p=(char *)realloc(*buffer,*curmax*sizeof(char));
|
|
||||||
else
|
|
||||||
p=(char *)malloc(*curmax*sizeof(char));
|
|
||||||
if (p==NULL)
|
if (p==NULL)
|
||||||
error(102,"staging buffer"); /* staging buffer overflow (fatal error) */
|
error(102,"staging buffer"); /* staging buffer overflow (fatal error) */
|
||||||
*buffer=p;
|
*buffer=p;
|
||||||
|
@ -122,7 +122,7 @@ SC_FUNC int cp_path(const char *root, const char *directory)
|
|||||||
len1= (root!=NULL) ? strlen(root) : 0;
|
len1= (root!=NULL) ? strlen(root) : 0;
|
||||||
add_slash1= (len1==0 || root[len1-1]!=DIRSEP_CHAR);
|
add_slash1= (len1==0 || root[len1-1]!=DIRSEP_CHAR);
|
||||||
len2= (directory!=NULL) ? strlen(directory) : 0;
|
len2= (directory!=NULL) ? strlen(directory) : 0;
|
||||||
add_slash2= (len2>0 && root[len2-1]!=DIRSEP_CHAR);
|
add_slash2= (len2>0 && directory[len2-1]!=DIRSEP_CHAR);
|
||||||
if (len1+add_slash1+len2+add_slash2>=(_MAX_PATH-MAXCODEPAGE))
|
if (len1+add_slash1+len2+add_slash2>=(_MAX_PATH-MAXCODEPAGE))
|
||||||
return FALSE; /* full filename may not fit */
|
return FALSE; /* full filename may not fit */
|
||||||
if (root!=NULL)
|
if (root!=NULL)
|
||||||
|
@ -63,10 +63,8 @@ static stringpair *insert_stringpair(stringpair *root,char *first,char *second,i
|
|||||||
cur->second=duplicatestring(second);
|
cur->second=duplicatestring(second);
|
||||||
cur->matchlength=matchlength;
|
cur->matchlength=matchlength;
|
||||||
if (cur->first==NULL || cur->second==NULL) {
|
if (cur->first==NULL || cur->second==NULL) {
|
||||||
if (cur->first!=NULL)
|
free(cur->first);
|
||||||
free(cur->first);
|
free(cur->second);
|
||||||
if (cur->second!=NULL)
|
|
||||||
free(cur->second);
|
|
||||||
free(cur);
|
free(cur);
|
||||||
return NULL;
|
return NULL;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -179,10 +179,12 @@ SC_FUNC void state_buildlist(int **list,int *listsize,int *count,int stateid)
|
|||||||
/* To avoid constantly calling malloc(), the list is grown by 4 states at
|
/* To avoid constantly calling malloc(), the list is grown by 4 states at
|
||||||
* a time.
|
* a time.
|
||||||
*/
|
*/
|
||||||
|
int *newlist;
|
||||||
*listsize+=4;
|
*listsize+=4;
|
||||||
*list=(int*)realloc(*list,*listsize*sizeof(int));
|
newlist=(int*)realloc(*list,*listsize*sizeof(int));
|
||||||
if (*list==NULL)
|
if (newlist==NULL)
|
||||||
error(103); /* insufficient memory */
|
error(103); /* insufficient memory */
|
||||||
|
*list=newlist;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
/* find the insertion point (the list has to stay sorted) */
|
/* find the insertion point (the list has to stay sorted) */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user