Skip to content

Commit af26e2a

Browse files
Denton-Lgitster
authored andcommitted
pack-bitmap.h: remove magic number
When we ran `make hdr-check` with the following patch diff --git a/Makefile b/Makefile index f879697..d8df4e3 100644 --- a/Makefile +++ b/Makefile @@ -2773,7 +2773,7 @@ CHK_HDRS = $(filter-out $(EXCEPT_HDRS),$(patsubst ./%,%,$(LIB_H))) HCO = $(patsubst %.h,%.hco,$(CHK_HDRS)) $(HCO): %.hco: %.h FORCE - $(QUIET_HDR)$(CC) -include git-compat-util.h -I. -o /dev/null -c -xc $< + $(QUIET_HDR)$(CC) -include git-compat-util.h -I. -o /dev/null -c -xc $(ALL_CFLAGS) $< .PHONY: hdr-check $(HCO) hdr-check: $(HCO) and with `DEVELOPER=1`, we got the following warning on Arch Linux: pack-bitmap.h:20:19: error: ‘BITMAP_IDX_SIGNATURE’ defined but not used [-Werror=unused-const-variable=] 20 | static const char BITMAP_IDX_SIGNATURE[] = {'B', 'I', 'T', 'M'}; | ^~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors "Use" the BITMAP_IDX_SIGNATURE variable by making the size of bitmap_disk_header.magic equal to the size of BITMAP_IDX_SIGNATURE, thereby eliminating the magic number (4). An alternative was to simply add MAYBE_UNUSED, however that does not eliminate the magic number. Another alternative was to change the definition to extern const char BITMAP_IDX_SIGNATURE[4]; However, this design was also not chosen as the static definition allows us to keep the declaration together for readability along with removing the magic number. Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b06fdea commit af26e2a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pack-bitmap.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ struct commit;
99
struct repository;
1010
struct rev_info;
1111

12+
static const char BITMAP_IDX_SIGNATURE[] = {'B', 'I', 'T', 'M'};
13+
1214
struct bitmap_disk_header {
13-
char magic[4];
15+
char magic[ARRAY_SIZE(BITMAP_IDX_SIGNATURE)];
1416
uint16_t version;
1517
uint16_t options;
1618
uint32_t entry_count;
1719
unsigned char checksum[GIT_MAX_RAWSZ];
1820
};
1921

20-
static const char BITMAP_IDX_SIGNATURE[] = {'B', 'I', 'T', 'M'};
21-
2222
#define NEEDS_BITMAP (1u<<22)
2323

2424
enum pack_bitmap_opts {

0 commit comments

Comments
 (0)