diff options
author | Simon Marlow <marlowsd@gmail.com> | 2013-10-25 10:44:29 +0100 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2013-10-25 10:50:48 +0100 |
commit | b724cd41a0aa1c650a48843efac42e85861eb9c6 (patch) | |
tree | f8db2f26baa800bbbbd01df1203c150b8686a79f /rts | |
parent | 36b042fbf60210ab6859d96e5b4b5e121085816d (diff) | |
download | haskell-b724cd41a0aa1c650a48843efac42e85861eb9c6.tar.gz |
Turn several nats into StgWord to avoid potential integer overflow (#7762)
Diffstat (limited to 'rts')
-rw-r--r-- | rts/sm/BlockAlloc.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/rts/sm/BlockAlloc.c b/rts/sm/BlockAlloc.c index 9f04c68a70..18c167fed0 100644 --- a/rts/sm/BlockAlloc.c +++ b/rts/sm/BlockAlloc.c @@ -260,10 +260,10 @@ split_free_block (bdescr *bd, W_ n, nat ln) } static bdescr * -alloc_mega_group (nat mblocks) +alloc_mega_group (StgWord mblocks) { bdescr *best, *bd, *prev; - nat n; + StgWord n; n = MBLOCK_GROUP_BLOCKS(mblocks); @@ -314,13 +314,13 @@ bdescr * allocGroup (W_ n) { bdescr *bd, *rem; - nat ln; + StgWord ln; if (n == 0) barf("allocGroup: requested zero blocks"); if (n >= BLOCKS_PER_MBLOCK) { - nat mblocks; + StgWord mblocks; mblocks = BLOCKS_TO_MBLOCKS(n); @@ -409,7 +409,7 @@ bdescr * allocLargeChunk (W_ min, W_ max) { bdescr *bd; - nat ln, lnmax; + StgWord ln, lnmax; if (min >= BLOCKS_PER_MBLOCK) { return allocGroup(max); @@ -531,7 +531,7 @@ free_mega_group (bdescr *mg) void freeGroup(bdescr *p) { - nat ln; + StgWord ln; // Todo: not true in multithreaded GC // ASSERT_SM_LOCK(); @@ -548,7 +548,7 @@ freeGroup(bdescr *p) if (p->blocks >= BLOCKS_PER_MBLOCK) { - nat mblocks; + StgWord mblocks; mblocks = BLOCKS_TO_MBLOCKS(p->blocks); // If this is an mgroup, make sure it has the right number of blocks @@ -692,13 +692,13 @@ countAllocdBlocks(bdescr *bd) void returnMemoryToOS(nat n /* megablocks */) { static bdescr *bd; - nat size; + StgWord size; bd = free_mblock_list; while ((n > 0) && (bd != NULL)) { size = BLOCKS_TO_MBLOCKS(bd->blocks); if (size > n) { - nat newSize = size - n; + StgWord newSize = size - n; char *freeAddr = MBLOCK_ROUND_DOWN(bd->start); freeAddr += newSize * MBLOCK_SIZE; bd->blocks = MBLOCK_GROUP_BLOCKS(newSize); @@ -746,12 +746,13 @@ void checkFreeListSanity(void) { bdescr *bd, *prev; - nat ln, min; + StgWord ln, min; min = 1; for (ln = 0; ln < MAX_FREE_LIST; ln++) { - IF_DEBUG(block_alloc, debugBelch("free block list [%d]:\n", ln)); + IF_DEBUG(block_alloc, + debugBelch("free block list [%" FMT_Word "]:\n", ln)); prev = NULL; for (bd = free_list[ln]; bd != NULL; prev = bd, bd = bd->link) @@ -817,7 +818,7 @@ countFreeList(void) { bdescr *bd; W_ total_blocks = 0; - nat ln; + StgWord ln; for (ln=0; ln < MAX_FREE_LIST; ln++) { for (bd = free_list[ln]; bd != NULL; bd = bd->link) { |