itry to use size_t

fix overflow handling bugs.
This commit is contained in:
Vitor Santos Costa 2012-12-14 19:35:26 +00:00
parent 84b0529060
commit 2e6360738c
5 changed files with 19 additions and 19 deletions

View File

@ -126,7 +126,7 @@ long long unsigned int tmalloc;
static inline char *
call_malloc(unsigned long int size)
call_malloc(size_t size)
{
CACHE_REGS
char *out;
@ -152,7 +152,7 @@ call_malloc(unsigned long int size)
}
char *
Yap_AllocCodeSpace(unsigned long int size)
Yap_AllocCodeSpace(size_t size)
{
size = AdjustSize(size);
return call_malloc(size);
@ -187,7 +187,7 @@ call_realloc(char *p, unsigned long int size)
}
char *
Yap_ReallocCodeSpace(char *p, unsigned long int size)
Yap_ReallocCodeSpace(char *p, size_t size)
{
size = AdjustSize(size);
return call_realloc(p, size);
@ -214,7 +214,7 @@ Yap_FreeCodeSpace(char *p)
}
char *
Yap_AllocAtomSpace(unsigned long int size)
Yap_AllocAtomSpace(size_t size)
{
size = AdjustSize(size);
return call_malloc(size);

View File

@ -809,7 +809,7 @@ Yap_BuildMegaClause(PredEntry *ap)
UInt sz;
MegaClause *mcl;
yamop *ptr;
UInt required;
size_t required;
UInt has_blobs = 0;
if (ap->PredFlags & (DynamicPredFlag|LogUpdatePredFlag|MegaClausePredFlag
@ -839,6 +839,12 @@ Yap_BuildMegaClause(PredEntry *ap)
sz -= (UInt)NEXTOP((yamop *)NULL,p) + sizeof(StaticClause);
}
required = sz*ap->cs.p_code.NOfClauses+sizeof(MegaClause)+(UInt)NEXTOP((yamop *)NULL,l);
while (!(mcl = (MegaClause *)Yap_AllocCodeSpace(required))) {
if (!Yap_growheap(FALSE, required, NULL)) {
/* just fail, the system will keep on going */
return;
}
}
#ifdef DEBUG
total_megaclause += required;
cl =
@ -846,12 +852,6 @@ Yap_BuildMegaClause(PredEntry *ap)
total_released += ap->cs.p_code.NOfClauses*cl->ClSize;
nof_megaclauses++;
#endif
while (!(mcl = (MegaClause *)Yap_AllocCodeSpace(required))) {
if (!Yap_growheap(FALSE, required, NULL)) {
/* just fail, the system will keep on going */
return;
}
}
Yap_ClauseSpace += required;
/* cool, it's our turn to do the conversion */
mcl->ClFlags = MegaMask | has_blobs;

View File

@ -1410,7 +1410,7 @@ growatomtable( USES_REGS1 )
int
Yap_growheap(int fix_code, UInt in_size, void *cip)
Yap_growheap(int fix_code, size_t in_size, void *cip)
{
CACHE_REGS
int res;
@ -1441,7 +1441,7 @@ Yap_growheap(int fix_code, UInt in_size, void *cip)
}
#if USE_SYSTEM_MALLOC
P = Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"malloc failed");
res = -1;
res = FALSE;
#else
res=do_growheap(fix_code, in_size, (struct intermediates *)cip, NULL, NULL, NULL PASS_REGS);
#endif

View File

@ -83,9 +83,9 @@ void STD_PROTO(Yap_init_agc, (void));
/* alloc.c */
void STD_PROTO(Yap_FreeCodeSpace,(char *));
char *STD_PROTO(Yap_AllocAtomSpace,(unsigned long int));
char *STD_PROTO(Yap_AllocCodeSpace,(unsigned long int));
char *STD_PROTO(Yap_ReallocCodeSpace,(char *,unsigned long int));
char *STD_PROTO(Yap_AllocAtomSpace,(size_t));
char *STD_PROTO(Yap_AllocCodeSpace,(size_t));
char *STD_PROTO(Yap_ReallocCodeSpace,(char *,size_t));
ADDR STD_PROTO(Yap_AllocFromForeignArea,(Int));
int STD_PROTO(Yap_ExtendWorkSpace,(Int));
void STD_PROTO(Yap_FreeAtomSpace,(char *));
@ -206,7 +206,7 @@ void STD_PROTO(Yap_AllocateDefaultArena, (Int, Int, int));
Int STD_PROTO(Yap_total_stack_shift_time,(void));
void STD_PROTO(Yap_InitGrowPreds, (void));
UInt STD_PROTO(Yap_InsertInGlobal, (CELL *, UInt));
int STD_PROTO(Yap_growheap, (int, UInt, void *));
int STD_PROTO(Yap_growheap, (int, size_t, void *));
int STD_PROTO(Yap_growstack, (long));
int STD_PROTO(Yap_growtrail, (long, int));
int STD_PROTO(Yap_growglobal, (CELL **));

View File

@ -66,10 +66,10 @@ typedef struct FREEB {
#if SIZEOF_INT_P==4
#define YAP_ALIGN 3
#define YAP_ALIGNMASK 0xfffffffc
#define YAP_ALIGNMASK ((CELL)(-4))
#else
#define YAP_ALIGN 7
#define YAP_ALIGNMASK 0xfffffff8L
#define YAP_ALIGNMASK ((CELL)(-8))
#endif /* ALIGN_LONGS */
#define AdjustSize(X) ((X+YAP_ALIGN) & YAP_ALIGNMASK)