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 <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Taylor Blau committed
Sep 9, 2021 at 19:24 UTC
ae44b5a4f3b091bc77adc4a70e7bfefd569b78a8
1 file changed
+6
-6
bulk-checkin.c
+6
-6
@@ -25,7 +25,7 @@ static struct bulk_checkin_state {
25
26
static void finish_bulk_checkin(struct bulk_checkin_state *state)
27
{
28
- struct object_id oid;
28
+ unsigned char hash[GIT_MAX_RAWSZ];
29
struct strbuf packname = STRBUF_INIT;
30
int i;
31
@@ -37,11 +37,11 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)
37
unlink(state->pack_tmp_name);
38
goto clear_exit;
39
} 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);
41
} 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,
45
state->offset);
46
close(fd);
47
}
@@ -49,7 +49,7 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)
49
strbuf_addf(&packname, "%s/pack/pack-", get_object_directory());
50
finish_tmp_packfile(&packname, state->pack_tmp_name,
51
state->written, state->nr_written,
52
- &state->pack_idx_opts, oid.hash);
52
+ &state->pack_idx_opts, hash);
53
for (i = 0; i < state->nr_written; i++)
54
free(state->written[i]);
55