notes: make GET_NIBBLE macro more robust
authorMichael Haggerty <mhagger@alum.mit.edu>
Sat, 26 Aug 2017 08:28:01 +0000 (10:28 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sat, 26 Aug 2017 16:21:01 +0000 (09:21 -0700)
Put parentheses around sha1. Otherwise it could fail for something
like

GET_NIBBLE(n, (unsigned char *)data);

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
notes.c
diff --git a/notes.c b/notes.c
index 8f47c202c58752b6d9d56852ae9c315e2f144769..71cc664b5008f4cc6b0c10c87abca0b3ace1b6c4 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -64,7 +64,7 @@ struct non_note {
 #define CLR_PTR_TYPE(ptr)       ((void *) ((uintptr_t) (ptr) & ~3))
 #define SET_PTR_TYPE(ptr, type) ((void *) ((uintptr_t) (ptr) | (type)))
 
-#define GET_NIBBLE(n, sha1) (((sha1[(n) >> 1]) >> ((~(n) & 0x01) << 2)) & 0x0f)
+#define GET_NIBBLE(n, sha1) ((((sha1)[(n) >> 1]) >> ((~(n) & 0x01) << 2)) & 0x0f)
 
 #define KEY_INDEX (GIT_SHA1_RAWSZ - 1)
 #define FANOUT_PATH_SEPARATORS ((GIT_SHA1_HEXSZ / 2) - 1)