Make integer overflow less likely to happen (#7762)
authorSimon Marlow <marlowsd@gmail.com>
Fri, 25 Oct 2013 09:40:23 +0000 (10:40 +0100)
committerSimon Marlow <marlowsd@gmail.com>
Fri, 25 Oct 2013 09:50:31 +0000 (10:50 +0100)
commit36b042fbf60210ab6859d96e5b4b5e121085816d
tree2a880696b639e48b2f57f8a4d6823a59a6ecd0f6
parent29be1a8afa6aece04ca85060662510a14d2ff8b0
Make integer overflow less likely to happen (#7762)

The particular problematic code in #7762 was this:

            nat newSize = size - n;
            char *freeAddr = MBLOCK_ROUND_DOWN(bd->start);
            freeAddr += newSize * MBLOCK_SIZE;
                        ^^^^^^^^^^^^^^^^^^^^^^  OVERFLOW!!!

For good measure, I'm going to fix the bug twice.  This patch fixes
the class of bugs of this kind, by making sure that any expressions
involving BLOCK_SIZE or MBLOCK_SIZE are promoted to unsigned long.  In
a separate patch, I'll fix a bunch of individual instances (including
the one above).
includes/rts/storage/Block.h