Skip to content

Commit f630cfd

Browse files
MadCodergitster
authored andcommitted
refactor: use bitsizeof() instead of 8 * sizeof()
Signed-off-by: Pierre Habouzit <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 67da52b commit f630cfd

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

git-compat-util.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
#endif
2727

2828
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
29+
#define bitsizeof(x) (CHAR_BIT * sizeof(x))
2930

3031
#ifdef __GNUC__
3132
#define TYPEOF(x) (__typeof__(x))
3233
#else
3334
#define TYPEOF(x)
3435
#endif
3536

36-
#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (sizeof(x) * 8 - (bits))))
37+
#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits))))
3738
#define HAS_MULTI_BITS(i) ((i) & ((i) - 1)) /* checks if an integer has more than 1 bit set */
3839

3940
/* Approximation of the length of the decimal representation of this type. */

sha1_file.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf,
11701170
size = c & 15;
11711171
shift = 4;
11721172
while (c & 0x80) {
1173-
if (len <= used || sizeof(long) * 8 <= shift) {
1173+
if (len <= used || bitsizeof(long) <= shift) {
11741174
error("bad object header");
11751175
return 0;
11761176
}

xdiff/xdiffi.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#define XDL_MAX_COST_MIN 256
2828
#define XDL_HEUR_MIN_COST 256
29-
#define XDL_LINE_MAX (long)((1UL << (8 * sizeof(long) - 1)) - 1)
29+
#define XDL_LINE_MAX (long)((1UL << (CHAR_BIT * sizeof(long) - 1)) - 1)
3030
#define XDL_SNAKE_CNT 20
3131
#define XDL_K_HEUR 4
3232

0 commit comments

Comments
 (0)