From 3d8cbbf2c35141377a86a57a862e74c270e59a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sat, 13 Mar 2021 17:17:30 +0100 Subject: [PATCH 1/2] block-sha1: drop trailing semicolon from macro definition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 23119ffb4e (block-sha1: put expanded macro parameters in parentheses, 2012-07-22) added a trailing semicolon to the definition of SHA_MIX without explanation. It doesn't matter with the current code, but make sure to avoid potential surprises by removing it again. This allows the macro to be used almost like a function: Users can combine it with operators of their choice, but still must not pass an expression with side-effects as a parameter, as it would be evaluated multiple times. Signed-off-by: René Scharfe Reviewed-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- block-sha1/sha1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block-sha1/sha1.c b/block-sha1/sha1.c index 8681031402..1bb6e7c069 100644 --- a/block-sha1/sha1.c +++ b/block-sha1/sha1.c @@ -70,7 +70,7 @@ * the input data, the next mix it from the 512-bit array. */ #define SHA_SRC(t) get_be32((unsigned char *) block + (t)*4) -#define SHA_MIX(t) SHA_ROL(W((t)+13) ^ W((t)+8) ^ W((t)+2) ^ W(t), 1); +#define SHA_MIX(t) SHA_ROL(W((t)+13) ^ W((t)+8) ^ W((t)+2) ^ W(t), 1) #define SHA_ROUND(t, input, fn, constant, A, B, C, D, E) do { \ unsigned int TEMP = input(t); setW(t, TEMP); \ From 116affac3f9e3d92d633e6fd766e541c1c5b0765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sat, 13 Mar 2021 17:17:37 +0100 Subject: [PATCH 2/2] mem-pool: drop trailing semicolon from macro definition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow BLOCK_GROWTH_SIZE to be used like an integer literal by removing the trailing semicolon from its definition. Also wrap the expression in parentheses, to allow it to be used with operators without leading to unexpected results. It doesn't matter for the current use site, but make it follow standard macro rules anyway to avoid future surprises. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- mem-pool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mem-pool.c b/mem-pool.c index 8401761dda..ccdcad2e3d 100644 --- a/mem-pool.c +++ b/mem-pool.c @@ -5,7 +5,7 @@ #include "cache.h" #include "mem-pool.h" -#define BLOCK_GROWTH_SIZE 1024*1024 - sizeof(struct mp_block); +#define BLOCK_GROWTH_SIZE (1024 * 1024 - sizeof(struct mp_block)) /* * Allocate a new mp_block and insert it after the block specified in