aboutsummaryrefslogtreecommitdiffstats
path: root/read-cache.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-10-02 09:29:30 +0200
committerJunio C Hamano <gitster@pobox.com>2025-10-02 09:32:32 -0700
commitf366bfe16b350240c70c487d180c76ddcb8a1b2d (patch)
tree8300e3b1b91d01b75bf7a08fc5642a0eea04302a /read-cache.c
parenthelp: report on whether or not Rust is enabled (diff)
downloadgit-f366bfe16b350240c70c487d180c76ddcb8a1b2d.tar.gz
git-f366bfe16b350240c70c487d180c76ddcb8a1b2d.zip
varint: use explicit width for integers
The varint subsystem currently uses implicit widths for integers. On the one hand we use `uintmax_t` for the actual value. On the other hand, we use `int` for the length of the encoded varint. Both of these have known maximum values, as we only support at most 16 bytes when encoding varints. Thus, we know that we won't ever exceed `uint64_t` for the actual value and `uint8_t` for the prefix length. Refactor the code to use explicit widths. Besides making the logic platform-independent, it also makes our life a bit easier in the next commit, where we reimplement "varint.c" in Rust. Suggested-by: Ezekiel Newren <ezekielnewren@gmail.com> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/read-cache.c b/read-cache.c
index 06ad74db22..41b44148b1 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1807,7 +1807,7 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool,
if (expand_name_field) {
const unsigned char *cp = (const unsigned char *)name;
- size_t strip_len, previous_len;
+ uint64_t strip_len, previous_len;
/* If we're at the beginning of a block, ignore the previous name */
strip_len = decode_varint(&cp);
@@ -2655,8 +2655,10 @@ static int ce_write_entry(struct hashfile *f, struct cache_entry *ce,
hashwrite(f, ce->name, len);
hashwrite(f, padding, align_padding_size(size, len));
} else {
- int common, to_remove, prefix_size;
+ int common, to_remove;
+ uint8_t prefix_size;
unsigned char to_remove_vi[16];
+
for (common = 0;
(common < previous_name->len &&
ce->name[common] &&