fix overflows

This commit is contained in:
Vítor Santos Costa 2011-12-22 11:42:26 +00:00
parent 551df1c70a
commit 1fde83d278
2 changed files with 14 additions and 9 deletions

View File

@ -1930,25 +1930,26 @@ YAP_StringToBuffer(Term t, char *buf, unsigned int bufsize)
return(FALSE); return(FALSE);
} else if (!IsIntTerm(Head)) { } else if (!IsIntTerm(Head)) {
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"user defined procedure"); Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"user defined procedure");
return(FALSE); return FALSE;
} }
i = IntOfTerm(Head); i = IntOfTerm(Head);
if (i < 0 || i > 255) { if (i < 0 || i > 255) {
Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"user defined procedure"); Yap_Error(REPRESENTATION_ERROR_CHARACTER_CODE,Head,"user defined procedure");
return(FALSE); return FALSE;
} }
buf[j++] = i; if (j == bufsize) {
if (j > bufsize) { buf[bufsize-1] = '\0';
buf[j-1] = '\0'; return FALSE;
return(FALSE); } else {
buf[j++] = i;
} }
t = TailOfTerm(t); t = TailOfTerm(t);
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR,t,"user defined procedure"); Yap_Error(INSTANTIATION_ERROR,t,"user defined procedure");
return(FALSE); return FALSE;
} else if (!IsPairTerm(t) && t != TermNil) { } else if (!IsPairTerm(t) && t != TermNil) {
Yap_Error(TYPE_ERROR_LIST, t, "user defined procedure"); Yap_Error(TYPE_ERROR_LIST, t, "user defined procedure");
return(FALSE); return FALSE;
} }
} }
buf[j] = '\0'; buf[j] = '\0';

View File

@ -1361,9 +1361,13 @@ static int
growatomtable( USES_REGS1 ) growatomtable( USES_REGS1 )
{ {
AtomHashEntry *ntb; AtomHashEntry *ntb;
UInt nsize = 4*AtomHashTableSize-1; UInt diff = 3*AtomHashTableSize-1, nsize;
UInt start_growth_time = Yap_cputime(), growth_time; UInt start_growth_time = Yap_cputime(), growth_time;
int gc_verbose = Yap_is_gc_verbose(); int gc_verbose = Yap_is_gc_verbose();
if (diff > 4*1024*1024)
diff = 4*1024*1024+7919;
else
nsize = nsize+7919;
LOCK(LOCAL_SignalLock); LOCK(LOCAL_SignalLock);
if (LOCAL_ActiveSignals == YAP_CDOVF_SIGNAL) { if (LOCAL_ActiveSignals == YAP_CDOVF_SIGNAL) {