fix format overflow bug;

fix variables in syntax error handler


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@445 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2002-04-16 19:48:45 +00:00
parent 6f8a9f3042
commit 0ddc85551f

View File

@ -2671,6 +2671,15 @@ p_write2 (void)
return (TRUE); return (TRUE);
} }
static void
clean_vars(VarEntry *p)
{
if (p == NULL) return;
p->VarAdr = TermNil;
clean_vars(p->VarLeft);
clean_vars(p->VarRight);
}
static Term static Term
syntax_error (TokEntry * tokptr) syntax_error (TokEntry * tokptr)
{ {
@ -2681,6 +2690,7 @@ syntax_error (TokEntry * tokptr)
Term *error = tf+3; Term *error = tf+3;
start = tokptr->TokPos; start = tokptr->TokPos;
clean_vars(VarTable);
while (1) { while (1) {
Term ts[2]; Term ts[2];
@ -2707,15 +2717,17 @@ syntax_error (TokEntry * tokptr)
t[0] = MkIntTerm(0); t[0] = MkIntTerm(0);
t[1] = StringToList(varinfo->VarRep); t[1] = StringToList(varinfo->VarRep);
if (varinfo->VarAdr == TermNil) { if (varinfo->VarAdr == TermNil) {
varinfo->VarAdr = MkVarTerm(); t[2] = varinfo->VarAdr = MkVarTerm();
} else {
t[2] = varinfo->VarAdr;
} }
t[2] = varinfo->VarAdr;
ts[0] = MkApplTerm(MkFunctor(LookupAtom("var"),3),3,t); ts[0] = MkApplTerm(MkFunctor(LookupAtom("var"),3),3,t);
} }
break; break;
case String_tok: case String_tok:
{ {
Term t0 = StringToList((char *)info); Term t0 = StringToList((char *)info);
fprintf(stderr,"looking at string %s\n", (char *)info);
ts[0] = MkApplTerm(MkFunctor(LookupAtom("string"),1),1,&t0); ts[0] = MkApplTerm(MkFunctor(LookupAtom("string"),1),1,&t0);
} }
break; break;
@ -3567,6 +3579,7 @@ format_putc(int sno, int ch) {
char *newbuf; char *newbuf;
if ((newbuf = AllocAtomSpace(new_max_size*sizeof(char))) == NULL) { if ((newbuf = AllocAtomSpace(new_max_size*sizeof(char))) == NULL) {
FreeAtomSpace(format_base);
Error(SYSTEM_ERROR, TermNil, "YAP could not grow heap for format/2"); Error(SYSTEM_ERROR, TermNil, "YAP could not grow heap for format/2");
return(EOF); return(EOF);
} }
@ -3698,6 +3711,7 @@ format(Term tail, Term args, int sno)
if (IsVarTerm (args) || !IsPairTerm (args)) if (IsVarTerm (args) || !IsPairTerm (args))
args = MkPairTerm (args, TermNil); args = MkPairTerm (args, TermNil);
format_base = format_ptr = AllocAtomSpace(FORMAT_MAX_SIZE*sizeof(char)); format_base = format_ptr = AllocAtomSpace(FORMAT_MAX_SIZE*sizeof(char));
format_max = format_base+FORMAT_MAX_SIZE;
if (format_ptr == NULL) { if (format_ptr == NULL) {
Error(INSTANTIATION_ERROR,tail,"format/2"); Error(INSTANTIATION_ERROR,tail,"format/2");
return(FALSE); return(FALSE);