From: Denton Liu <liu.denton@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Cc: Jeff King <peff@peff.net>
Subject: [PATCH v2 3/4] pack-bitmap.h: remove magic number
Date: Wed, 25 Sep 2019 01:20:59 -0700 [thread overview]
Message-ID: <50e37c16f9715bb6bc41940545c779f6aa9f6be4.1569398897.git.liu.denton@gmail.com> (raw)
In-Reply-To: <cover.1569398897.git.liu.denton@gmail.com>
When we ran `make hdr-check` with the following patch
diff --git a/Makefile b/Makefile
index f879697ea3..d8df4e316b 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 <liu.denton@gmail.com>
---
pack-bitmap.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/pack-bitmap.h b/pack-bitmap.h
index 00de3ec8e4..466c5afa09 100644
--- a/pack-bitmap.h
+++ b/pack-bitmap.h
@@ -9,16 +9,16 @@ struct commit;
struct repository;
struct rev_info;
+static const char BITMAP_IDX_SIGNATURE[] = {'B', 'I', 'T', 'M'};
+
struct bitmap_disk_header {
- char magic[4];
+ char magic[ARRAY_SIZE(BITMAP_IDX_SIGNATURE)];
uint16_t version;
uint16_t options;
uint32_t entry_count;
unsigned char checksum[GIT_MAX_RAWSZ];
};
-static const char BITMAP_IDX_SIGNATURE[] = {'B', 'I', 'T', 'M'};
-
#define NEEDS_BITMAP (1u<<22)
enum pack_bitmap_opts {
--
2.23.0.248.g3a9dd8fb08
next prev parent reply other threads:[~2019-09-25 8:21 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-23 18:34 [PATCH 0/3] fixes related to `make hdr-check` Denton Liu
2019-09-23 18:34 ` [PATCH 1/3] Makefile: use $(ALL_CFLAGS) in $(HCO) target Denton Liu
2019-09-26 12:49 ` Johannes Schindelin
2019-09-26 17:38 ` Denton Liu
2019-09-26 19:47 ` Johannes Schindelin
2019-09-28 4:59 ` Junio C Hamano
2019-09-23 18:34 ` [PATCH 2/3] apply.h: include missing header Denton Liu
2019-09-23 18:34 ` [PATCH 3/3] promisor-remote.h: " Denton Liu
2019-09-24 9:08 ` [PATCH 4/3] pack-bitmap.h: fix unused variable warning Denton Liu
2019-09-24 21:34 ` Jeff King
2019-09-24 21:38 ` Jeff King
2019-09-25 8:20 ` [PATCH v2 0/4] fixes related to `make hdr-check` Denton Liu
2019-09-25 8:20 ` [PATCH v2 1/4] apply.h: include missing header Denton Liu
2019-09-25 8:20 ` [PATCH v2 2/4] promisor-remote.h: " Denton Liu
2019-09-25 8:20 ` Denton Liu [this message]
2019-09-25 8:21 ` [PATCH v2 4/4] Makefile: emulate compile in $(HCO) target better Denton Liu
2019-10-02 15:41 ` Jeff King
2019-09-26 12:57 ` [PATCH 0/3] fixes related to `make hdr-check` Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50e37c16f9715bb6bc41940545c779f6aa9f6be4.1569398897.git.liu.denton@gmail.com \
--to=liu.denton@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).