Skip to content

Commit ae44b5a

Browse files
ttaylorrgitster
authored andcommitted
bulk-checkin.c: store checksum directly
finish_bulk_checkin() stores the checksum from finalize_hashfile() by writing to the `hash` member of `struct object_id`, but that hash has nothing to do with an object id (it's just a convenient location that happens to be sized correctly). Store the hash directly in an unsigned char array. This behaves the same as writing to the `hash` member, but makes the intent clearer (and avoids allocating an extra four bytes for the `algo` member of `struct object_id`). It likewise prevents the possibility of a segfault when reading `algo` (e.g., by calling `oid_to_hex()`) if it is uninitialized. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0c41a88 commit ae44b5a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

bulk-checkin.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static struct bulk_checkin_state {
2525

2626
static void finish_bulk_checkin(struct bulk_checkin_state *state)
2727
{
28-
struct object_id oid;
28+
unsigned char hash[GIT_MAX_RAWSZ];
2929
struct strbuf packname = STRBUF_INIT;
3030
int i;
3131

@@ -37,19 +37,19 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)
3737
unlink(state->pack_tmp_name);
3838
goto clear_exit;
3939
} else if (state->nr_written == 1) {
40-
finalize_hashfile(state->f, oid.hash, CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE);
40+
finalize_hashfile(state->f, hash, CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE);
4141
} else {
42-
int fd = finalize_hashfile(state->f, oid.hash, 0);
43-
fixup_pack_header_footer(fd, oid.hash, state->pack_tmp_name,
44-
state->nr_written, oid.hash,
42+
int fd = finalize_hashfile(state->f, hash, 0);
43+
fixup_pack_header_footer(fd, hash, state->pack_tmp_name,
44+
state->nr_written, hash,
4545
state->offset);
4646
close(fd);
4747
}
4848

4949
strbuf_addf(&packname, "%s/pack/pack-", get_object_directory());
5050
finish_tmp_packfile(&packname, state->pack_tmp_name,
5151
state->written, state->nr_written,
52-
&state->pack_idx_opts, oid.hash);
52+
&state->pack_idx_opts, hash);
5353
for (i = 0; i < state->nr_written; i++)
5454
free(state->written[i]);
5555

0 commit comments

Comments
 (0)