From 0b8a66f8773b9fd286aac44accfa6ddb4229f0d7 Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Tue, 15 Aug 2017 00:38:09 +0200 Subject: [PATCH] kernel: umem: fix img_get macro The img_get macro used to subtract 1 to the argument provided before computing the porinter to the image. I can't remember why it did so. However the expression was wrong. Coverity found the issue: Operands don't affect result (CONSTANT_EXPRESSION_RESULT) CID: 155616, 155606, 155598, 155597, 155596, 155587, 155580, 155578, 155577, 155576, 155568, 155566 Simply removing the subtraction seems the obvious fix. --- sys/src/kern/port/umem/images.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/src/kern/port/umem/images.c b/sys/src/kern/port/umem/images.c index 45a883f..704cb9f 100644 --- a/sys/src/kern/port/umem/images.c +++ b/sys/src/kern/port/umem/images.c @@ -88,7 +88,7 @@ static RWlock pool_lock; /* to grow chunks or modify free list */ static ImagePool pool; #define img_hash(path) ((uint8_t)((path*(PSTEP+1))&(PSTEP-1))) -#define img_get(ptr) (&(pool.chunks[(uint8_t)(ptr-1)>>8]->images[(uint8_t)(ptr-1)&(PSTEP-1)])) +#define img_get(ptr) (&(pool.chunks[(uint8_t)((ptr)>>8)]->images[(uint8_t)((ptr)&(PSTEP-1))])) void imagepool_init(short max_images)