From: hno <> Date: Sat, 6 Apr 2002 22:06:13 +0000 (+0000) Subject: Cleaned up pointer arithmetic X-Git-Tag: SQUID_3_0_PRE1~1121 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6e7d3e03ad76b4602ee232b09cd4d21de12e3d2e;p=thirdparty%2Fsquid.git Cleaned up pointer arithmetic * (void *) cannot be used in arithmetic * It is not safe to cast pointers to int (size downcast) --- diff --git a/lib/MemPool.c b/lib/MemPool.c index 4e5b13dd13..6af80359a4 100644 --- a/lib/MemPool.c +++ b/lib/MemPool.c @@ -1,6 +1,6 @@ /* - * $Id: MemPool.c,v 1.7 2002/04/06 08:49:26 adrian Exp $ + * $Id: MemPool.c,v 1.8 2002/04/06 15:06:13 hno Exp $ * * DEBUG: section 63 Low Level Memory Pool Management * AUTHOR: Alex Rousskov, Andres Kroonmaa @@ -184,7 +184,12 @@ memPoolSetIdleLimit(size_t new_idle_limit) static int memCompChunks(MemChunk * chunkA, MemChunk * chunkB) { - return chunkA->objCache - chunkB->objCache; + if (chunkA > chunkB) + return 1; + else if (chunkA < chunkB) + return -1; + else + return 0; } /* Compare object to chunk */ @@ -192,7 +197,7 @@ static int memCompObjChunks(void *obj, MemChunk * chunk) { int bounds; - bounds = obj - chunk->objCache; + bounds = (char *)obj - (char *)chunk->objCache; if (bounds < 0) return -1; if (bounds < lastPool->chunk_size) @@ -212,7 +217,7 @@ memPoolChunkNew(MemPool * pool) Free = chunk->freeList = chunk->objCache; for (i = 1; i < pool->chunk_capacity; i++) { - *Free = (void *) Free + pool->obj_size; + *Free = (void *) ((char *)Free + pool->obj_size); Free = *Free; } chunk->nextFreeChunk = pool->nextFreeChunk;