From a52317b9c2bad9891c2061e1d12a9652093db0bf Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Sun, 17 May 2009 12:26:09 -0700 Subject: [PATCH] fix Yap_shift_visit for malloc: a few miscalculations... --- C/grow.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/C/grow.c b/C/grow.c index 8d4b49f41..c4de617fc 100644 --- a/C/grow.c +++ b/C/grow.c @@ -1596,8 +1596,8 @@ Yap_shift_visit(CELL **to_visit, CELL ***to_visit_maxp) { #if USE_SYSTEM_MALLOC CELL **to_visit_max = *to_visit_maxp; - Int sz1 = (CELL)to_visit_max-(CELL)to_visit; - Int sz0 = AuxTop - (ADDR)to_visit_maxp, sz, dsz; + Int sz1 = (CELL)to_visit-(CELL)to_visit_max; + Int sz0 = AuxTop - (ADDR)to_visit_max, sz, dsz; char *newb = Yap_ExpandPreAllocCodeSpace(0, NULL); if (newb == NULL) { @@ -1608,6 +1608,10 @@ Yap_shift_visit(CELL **to_visit, CELL ***to_visit_maxp) sz = AuxTop-newb; /* how much we grew */ dsz = sz-sz0; + if (dsz == 0) { + Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"cannot allocate temporary space for unification (%p)", to_visit); + return to_visit; + } /* copy whole block to end */ cpcellsd((CELL *)newb, (CELL *)(newb+dsz), sz0/sizeof(CELL)); /* base pointer is block start */