FIX: InitCPred and friends should check for overflow.

This commit is contained in:
Vítor Santos Costa 2008-09-24 00:59:41 +01:00
parent 139f591458
commit abcb8f99fe
2 changed files with 77 additions and 24 deletions

View File

@ -759,6 +759,8 @@ Yap_NewPredPropByAtom(AtomEntry *ae, Term cur_mod)
{ {
Prop p0; Prop p0;
PredEntry *p = (PredEntry *) Yap_AllocAtomSpace(sizeof(*p)); PredEntry *p = (PredEntry *) Yap_AllocAtomSpace(sizeof(*p));
if (!p)
return NIL;
/* Printf("entering %s:%s/0\n", RepAtom(AtomOfTerm(cur_mod))->StrOfAE, ae->StrOfAE); */ /* Printf("entering %s:%s/0\n", RepAtom(AtomOfTerm(cur_mod))->StrOfAE, ae->StrOfAE); */

View File

@ -482,15 +482,28 @@ InitDebug(void)
void void
Yap_InitCPred(char *Name, unsigned long int Arity, CPredicate code, int flags) Yap_InitCPred(char *Name, unsigned long int Arity, CPredicate code, int flags)
{ {
Atom atom = Yap_FullLookupAtom(Name); Atom atom = NIL;
PredEntry *pe; PredEntry *pe = NULL;
yamop *p_code; yamop *p_code;
StaticClause *cl = NULL; StaticClause *cl = NULL;
if (Arity) while (atom == NIL) {
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule)); atom = Yap_FullLookupAtom(Name);
else if (atom == NIL && !Yap_growheap(FALSE, 0L, NULL)) {
pe = RepPredProp(PredPropByAtom(atom,CurrentModule)); Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
return;
}
}
while (pe == NULL) {
if (Arity)
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule));
else
pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
return;
}
}
if (pe->PredFlags & CPredFlag) { if (pe->PredFlags & CPredFlag) {
/* already exists */ /* already exists */
cl = ClauseCodeToStaticClause(pe->CodeOfPred); cl = ClauseCodeToStaticClause(pe->CodeOfPred);
@ -558,16 +571,28 @@ Yap_InitCPred(char *Name, unsigned long int Arity, CPredicate code, int flags)
void void
Yap_InitCmpPred(char *Name, unsigned long int Arity, CmpPredicate cmp_code, int flags) Yap_InitCmpPred(char *Name, unsigned long int Arity, CmpPredicate cmp_code, int flags)
{ {
Atom atom = Yap_LookupAtom(Name); Atom atom = NIL;
PredEntry *pe; PredEntry *pe = NULL;
yamop *p_code = NULL; yamop *p_code = NULL;
StaticClause *cl = NULL; StaticClause *cl = NULL;
if (Arity) { while (atom == NIL) {
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule)); atom = Yap_FullLookupAtom(Name);
} else { if (atom == NIL && !Yap_growheap(FALSE, 0L, NULL)) {
pe = RepPredProp(PredPropByAtom(atom,CurrentModule)); Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
return;
}
} }
while (pe == NULL) {
if (Arity)
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule));
else
pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
return;
}
}
if (pe->PredFlags & CPredFlag) { if (pe->PredFlags & CPredFlag) {
p_code = pe->CodeOfPred; p_code = pe->CodeOfPred;
/* already exists */ /* already exists */
@ -612,13 +637,26 @@ Yap_InitCmpPred(char *Name, unsigned long int Arity, CmpPredicate cmp_code, int
void void
Yap_InitAsmPred(char *Name, unsigned long int Arity, int code, CPredicate def, int flags) Yap_InitAsmPred(char *Name, unsigned long int Arity, int code, CPredicate def, int flags)
{ {
Atom atom = Yap_FullLookupAtom(Name); Atom atom = NIL;
PredEntry *pe; PredEntry *pe = NULL;
if (Arity) while (atom == NIL) {
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule)); atom = Yap_FullLookupAtom(Name);
else if (atom == NIL && !Yap_growheap(FALSE, 0L, NULL)) {
pe = RepPredProp(PredPropByAtom(atom,CurrentModule)); Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
return;
}
}
while (pe == NULL) {
if (Arity)
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule));
else
pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
return;
}
}
pe->PredFlags = flags | AsmPredFlag | StandardPredFlag | (code); pe->PredFlags = flags | AsmPredFlag | StandardPredFlag | (code);
pe->cs.f_code = def; pe->cs.f_code = def;
pe->ModuleOfPred = CurrentModule; pe->ModuleOfPred = CurrentModule;
@ -732,13 +770,26 @@ Yap_InitCPredBack(char *Name, unsigned long int Arity,
CPredicate Cont, int flags) CPredicate Cont, int flags)
#endif #endif
{ {
PredEntry *pe; PredEntry *pe = NULL;
Atom atom = Yap_FullLookupAtom(Name); Atom atom = NIL;
if (Arity) while (atom == NIL) {
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule)); atom = Yap_FullLookupAtom(Name);
else if (atom == NIL && !Yap_growheap(FALSE, 0L, NULL)) {
pe = RepPredProp(PredPropByAtom(atom,CurrentModule)); Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
return;
}
}
while (pe == NULL) {
if (Arity)
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule));
else
pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
return;
}
}
if (pe->cs.p_code.FirstClause != NIL) if (pe->cs.p_code.FirstClause != NIL)
{ {
#ifdef CUT_C #ifdef CUT_C