Skip to content

Commit 2ef74b5

Browse files
committed
shallow: give write_one_shallow() its own hex buffer
The previous fix reuses the local `hex` variable that is already computed at the top of `write_one_shallow()`. That works today, but `oid_to_hex()` returns a pointer into a small rotating buffer, so it is not stable across an unrelated call to `oid_to_hex()` from the same thread. A future edit that adds such a call between the assignment and the last user of `hex` would silently corrupt the output. Move `write_one_shallow()` off the rotating buffer entirely by using a local buffer instead. The current users of that `hex` variable are unchanged. Suggested-by: Junio C Hamano <gitster@pobox.com> Assisted-by: Claude Opus 4.7 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent e581bc9 commit 2ef74b5

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

shallow.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,9 @@ struct write_shallow_data {
359359
static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
360360
{
361361
struct write_shallow_data *data = cb_data;
362-
const char *hex = oid_to_hex(&graft->oid);
362+
char hex[GIT_MAX_HEXSZ + 1];
363+
364+
oid_to_hex_r(hex, &graft->oid);
363365
if (graft->nr_parent != -1)
364366
return 0;
365367
if (data->flags & QUICK) {

0 commit comments

Comments
 (0)