From: Johannes Schindelin via GitGitGadget Date: Fri, 10 Jul 2026 11:39:36 GMT Subject: [PATCH v2 12/12] shallow: give write_one_shallow() its own hex buffer Message-ID: <2ef74b52fadc2bbffe7414b27db739546ab369c1.1783683577.git.gitgitgadget@gmail.com> In-Reply-To: From: Johannes Schindelin 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 Assisted-by: Claude Opus 4.7 Signed-off-by: Johannes Schindelin --- shallow.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shallow.c b/shallow.c index 2f96db5170..c567cc3c69 100644 --- a/shallow.c +++ b/shallow.c @@ -359,7 +359,9 @@ struct write_shallow_data { static int write_one_shallow(const struct commit_graft *graft, void *cb_data) { struct write_shallow_data *data = cb_data; - const char *hex = oid_to_hex(&graft->oid); + char hex[GIT_MAX_HEXSZ + 1]; + + oid_to_hex_r(hex, &graft->oid); if (graft->nr_parent != -1) return 0; if (data->flags & QUICK) { -- gitgitgadget