Fix compile warnings in dlmalloc

The origional code was using on odd reference to get to the first
real element in av_[].  The first two elements of the array are
not used for actual bins, but for house keeping.  If we are more
explicit about how use the first few elements we can get rid of the
warnings:

dlmalloc.c: In function 'malloc_extend_top':
dlmalloc.c:1971: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:1999: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2029: warning: dereferencing type-punned pointer will break strict-aliasing rules
...

The logic of how this code came to be is:
	bin_at(0) = (char*)&(av_[2]) - 2*SIZE_SZ

SIZE_SZ is the size of pointer, and av_ is arry of pointers so:
	bin_at(0) = &(av_[0])

Going from there to bin_at(0)->fd or bin_at(0)->size should be straight forward.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
This commit is contained in:
Kumar Gala 2008-07-30 08:01:15 -05:00 committed by Wolfgang Denk
parent 3f9ae1a5d4
commit 57c219ad5d

View File

@ -1457,7 +1457,7 @@ typedef struct malloc_chunk* mbinptr;
indexing, maintain locality, and avoid some initialization tests.
*/
#define top (bin_at(0)->fd) /* The topmost chunk */
#define top (av_[2]) /* The topmost chunk */
#define last_remainder (bin_at(1)) /* remainder from last split */
@ -1552,13 +1552,14 @@ void malloc_bin_reloc (void)
#define BINBLOCKWIDTH 4 /* bins per block */
#define binblocks (bin_at(0)->size) /* bitvector of nonempty blocks */
#define binblocks_r ((INTERNAL_SIZE_T)av_[1]) /* bitvector of nonempty blocks */
#define binblocks_w (av_[1])
/* bin<->block macros */
#define idx2binblock(ix) ((unsigned)1 << (ix / BINBLOCKWIDTH))
#define mark_binblock(ii) (binblocks |= idx2binblock(ii))
#define clear_binblock(ii) (binblocks &= ~(idx2binblock(ii)))
#define mark_binblock(ii) (binblocks_w = (mbinptr)(binblocks_r | idx2binblock(ii)))
#define clear_binblock(ii) (binblocks_w = (mbinptr)(binblocks_r & ~(idx2binblock(ii))))
@ -2250,17 +2251,17 @@ Void_t* mALLOc(bytes) size_t bytes;
search for best fitting chunk by scanning bins in blockwidth units.
*/
if ( (block = idx2binblock(idx)) <= binblocks)
if ( (block = idx2binblock(idx)) <= binblocks_r)
{
/* Get to the first marked block */
if ( (block & binblocks) == 0)
if ( (block & binblocks_r) == 0)
{
/* force to an even block boundary */
idx = (idx & ~(BINBLOCKWIDTH - 1)) + BINBLOCKWIDTH;
block <<= 1;
while ((block & binblocks) == 0)
while ((block & binblocks_r) == 0)
{
idx += BINBLOCKWIDTH;
block <<= 1;
@ -2315,7 +2316,7 @@ Void_t* mALLOc(bytes) size_t bytes;
{
if ((startidx & (BINBLOCKWIDTH - 1)) == 0)
{
binblocks &= ~block;
av_[1] = (mbinptr)(binblocks_r & ~block);
break;
}
--startidx;
@ -2324,9 +2325,9 @@ Void_t* mALLOc(bytes) size_t bytes;
/* Get to the next possibly nonempty block */
if ( (block <<= 1) <= binblocks && (block != 0) )
if ( (block <<= 1) <= binblocks_r && (block != 0) )
{
while ((block & binblocks) == 0)
while ((block & binblocks_r) == 0)
{
idx += BINBLOCKWIDTH;
block <<= 1;