shallow.c: avoid theoretical pointer wrap-around
The expression info->free+size is technically undefined behaviour in exactly the case we want to test for. Moreover, the compiler is likely to translate the expression to (unsigned long)info->free + size > (unsigned long)info->end where there's at least a theoretical chance that the LHS could wrap around 0, giving a false negative. This might as well be written using pointer subtraction avoiding these issues. Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Rasmus Villemoes committed
Dec 6, 2016 at 19:53 UTC
381aa8e73070646933520e1133a81ab4ba383891
1 file changed
+1
-1
shallow.c
+1
-1
@@ -368,7 +368,7 @@ static uint32_t *paint_alloc(struct paint_info *info)
368
unsigned nr = (info->nr_bits + 31) / 32;
369
unsigned size = nr * sizeof(uint32_t);
370
void *p;
371
- if (!info->pool_count || info->free + size > info->end) {
371
+ if (!info->pool_count || size > info->end - info->free) {
372
if (size > POOL_SIZE)
373
die("BUG: pool size too small for %d in paint_alloc()",
374
size);