Re: memCompChunks

From: Henrik Nordstrom <hno@dont-contact.us>
Date: Mon, 8 Apr 2002 12:17:57 +0200

Hmm.. reading the other function again:

/* Compare object to chunk */
static int
memCompObjChunks(void *obj, MemChunk * chunk)
{
    int bounds;
    bounds = (char *)obj - (char *)chunk->objCache;
    if (bounds < 0)
        return -1;
    if (bounds < lastPool->chunk_size)
        return 0;
    return 1;
}

I see two problems here.. bounds may overflow (both directions), and
what is lastPool? Shuln't the size be picked up from chunk?

The overflow is easily avoided by not using the bounds variable but
directly compare the pointers. The second I don't know.

The code now reads:

/* Compare object to chunk */
/* XXX Note: this depends on lastPool */
static int
memCompObjChunks(void *obj, MemChunk * chunk)
{
    if (obj < chunk->objCache)
        return -1;
    if (obj < (void *)((char *)chunk->objCache +
lastPool->chunk_size))
        return 0;
    return 1;
}

Regards
Henrik
Received on Mon Apr 08 2002 - 04:18:28 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:14:58 MST