The `read_u8()` helper function internal to pack-bitmap.c was defined in b5007211b6 (pack-bitmap: do not use gcc packed attribute, 2014-11-27). Prior to b5007211b6, callers within pack-bitmap.c would read an individual unsigned integer by doing something like: struct bitmap_disk_entry *e; e = (struct bitmap_disk_entry *)(index->map + index->map_pos); index->map_pos += sizeof(*e); ...which relied on the fact that the `bitmap_disk_entry` struct was defined with `__attribute((packed))`, which b5007211b6 sought to get rid of since the `__attribute__` flag is a noop on some compilers (which makes the above code rely on the absence of padding to be correct). So b5007211b6 got rid of the above convention and replaced it by reading individual fields of that structure with a `read_u8()` helper that reads from the region of memory pointed to by `->map`, and updates the `->map_pos` pointer accordingly. But this forces callers to be intimately aware of `bitmap_git->map` and `bitmap_git->map_pos`. Instead, teach `read_u8()` to take a `struct bitmap_index *` directly, and avoid having callers deal with the internals themselves. Signed-off-by: Taylor Blau <me@xxxxxxxxxxxx> --- pack-bitmap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pack-bitmap.c b/pack-bitmap.c index ca7c81b5c9..d8ba252ba1 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -251,9 +251,9 @@ static inline uint32_t read_be32(const unsigned char *buffer, size_t *pos) return result; } -static inline uint8_t read_u8(const unsigned char *buffer, size_t *pos) +static inline uint8_t read_u8(struct bitmap_index *bitmap_git) { - return buffer[(*pos)++]; + return bitmap_git->map[bitmap_git->map_pos++]; } #define MAX_XOR_OFFSET 160 @@ -283,8 +283,8 @@ static int load_bitmap_entries_v1(struct bitmap_index *index) return error(_("corrupt ewah bitmap: truncated header for entry %d"), i); commit_idx_pos = read_be32(index->map, &index->map_pos); - xor_offset = read_u8(index->map, &index->map_pos); - flags = read_u8(index->map, &index->map_pos); + xor_offset = read_u8(index); + flags = read_u8(index); if (nth_bitmap_object_oid(index, &oid, commit_idx_pos) < 0) return error(_("corrupt ewah bitmap: commit index %u out of range"), @@ -780,7 +780,7 @@ static struct stored_bitmap *lazy_bitmap_for_commit(struct bitmap_index *bitmap_ } bitmap_git->map_pos += sizeof(uint32_t) + sizeof(uint8_t); - xor_flags = read_u8(bitmap_git->map, &bitmap_git->map_pos); + xor_flags = read_u8(bitmap_git); bitmap = read_bitmap_1(bitmap_git); if (!bitmap) @@ -821,7 +821,7 @@ static struct stored_bitmap *lazy_bitmap_for_commit(struct bitmap_index *bitmap_ * ewah bitmap. */ bitmap_git->map_pos += sizeof(uint32_t) + sizeof(uint8_t); - flags = read_u8(bitmap_git->map, &bitmap_git->map_pos); + flags = read_u8(bitmap_git); bitmap = read_bitmap_1(bitmap_git); if (!bitmap) -- 2.40.0.77.gd564125b3f