emit/__emit: Fix multiple occurences of NULL pointer dereference

This commit is contained in:
Daniel_Cortez 2017-11-12 18:25:38 +07:00
parent 28c69cd8c8
commit f921451c8a

View File

@ -5869,9 +5869,9 @@ static void emit_param_num(char *name,ucell *p,int size)
sym=findloc(str); sym=findloc(str);
if (sym==NULL) if (sym==NULL)
sym=findglb(str,sSTATEVAR); sym=findglb(str,sSTATEVAR);
if (sym==NULL || (sym->ident!=iFUNCTN && sym->ident!=iREFFUNC && (sym->usage & uDEFINE)==0) || sym->ident==iLABEL) if (sym==NULL || (sym->ident!=iFUNCTN && sym->ident!=iREFFUNC && (sym->usage & uDEFINE)==0) || sym->ident==iLABEL) {
error(17,str); /* undefined symbol */ error(17,str); /* undefined symbol */
if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) { } else if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) {
if ((sym->usage & uNATIVE)!=0 && (sym->usage & uREAD)==0 && sym->addr>=0) if ((sym->usage & uNATIVE)!=0 && (sym->usage & uREAD)==0 && sym->addr>=0)
sym->addr=ntv_funcid++; sym->addr=ntv_funcid++;
p[curp]=sym->addr; p[curp]=sym->addr;
@ -5892,16 +5892,14 @@ static void emit_param_num(char *name,ucell *p,int size)
break; break;
} else { } else {
strcpy(ival+1,str); strcpy(ival+1,str);
error(1,sc_tokens[tSYMBOL-tFIRST],ival);
break;
} /* if */ } /* if */
} else {
if (tok<tFIRST)
sprintf(ival,"%c",(char)tok);
else
strcpy(ival,sc_tokens[tok-tFIRST]);
} /* if */ } /* if */
if (tok<tFIRST)
sprintf(ival,"%c",(char)tok);
else
strcpy(ival,sc_tokens[tok-tFIRST]);
error(1,sc_tokens[tSYMBOL-tFIRST],ival); error(1,sc_tokens[tSYMBOL-tFIRST],ival);
break;
} /* switch */ } /* switch */
} while (++curp<size); } while (++curp<size);
} }
@ -5923,12 +5921,18 @@ static void emit_param_data(char *name,ucell *p,int size)
break; break;
case tSYMBOL: case tSYMBOL:
sym=findloc(str); sym=findloc(str);
if (sym==NULL) if (sym!=NULL) {
if (sym->vclass!=sSTATIC) {
error(17,str); /* undefined symbol */
continue;
}
} else {
sym=findglb(str,sSTATIC); sym=findglb(str,sSTATIC);
else if (sym->vclass!=sSTATIC) if (sym==NULL) {
error(17,str); error(17,str); /* undefined symbol */
if (sym==NULL) continue;
error(17,str); }
}
markusage(sym,uREAD|uWRITTEN); markusage(sym,uREAD|uWRITTEN);
p[curp]=sym->addr; p[curp]=sym->addr;
break; break;
@ -6103,8 +6107,9 @@ static void OPHANDLER_CALL emit_do_case(char *name)
sym=fetchlab(str); sym=fetchlab(str);
if (sym==NULL) if (sym==NULL)
error(17,str); /* undefined symbol */ error(17,str); /* undefined symbol */
outval(sym->addr,FALSE); else
stgwrite("\n"); val=sym->addr;
outval(val,TRUE);
code_idx+=opargs(2)+opcodes(0); code_idx+=opargs(2)+opcodes(0);
} }
@ -6135,15 +6140,17 @@ static void OPHANDLER_CALL emit_do_call(char *name)
if (tok!=tSYMBOL) if (tok!=tSYMBOL)
emit_invalid_token(tSYMBOL,tok); emit_invalid_token(tSYMBOL,tok);
sym=findglb(str,sGLOBAL); sym=findglb(str,sGLOBAL);
if (sym==NULL) if (sym==NULL) {
error(12); /* invalid function call */ error(12); /* invalid function call */
stgwrite("\t"); } else {
stgwrite(name); stgwrite("\t");
stgwrite(" ."); stgwrite(name);
stgwrite(str); stgwrite(" .");
stgwrite("\n"); stgwrite(str);
code_idx+=opcodes(1)+opargs(1); stgwrite("\n");
markusage(sym,uREAD); code_idx+=opcodes(1)+opargs(1);
markusage(sym,uREAD);
}
} }
static EMIT_OPCODE emit_opcodelist[] = { static EMIT_OPCODE emit_opcodelist[] = {