Skip to content

Commit bf42772

Browse files
mhaggergitster
authored andcommitted
register_ref(): make a copy of the bad reference SHA-1
The lifetime of the sha1 parameter passed to an each_ref_fn callback is not guaranteed, so make a copy for later use. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 66ce036 commit bf42772

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

bisect.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
static struct sha1_array good_revs;
1616
static struct sha1_array skipped_revs;
1717

18-
static const unsigned char *current_bad_sha1;
18+
static unsigned char *current_bad_sha1;
1919

2020
static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL};
2121
static const char *argv_show_branch[] = {"show-branch", NULL, NULL};
@@ -404,7 +404,8 @@ static int register_ref(const char *refname, const unsigned char *sha1,
404404
int flags, void *cb_data)
405405
{
406406
if (!strcmp(refname, "bad")) {
407-
current_bad_sha1 = sha1;
407+
current_bad_sha1 = xmalloc(20);
408+
hashcpy(current_bad_sha1, sha1);
408409
} else if (!prefixcmp(refname, "good-")) {
409410
sha1_array_append(&good_revs, sha1);
410411
} else if (!prefixcmp(refname, "skip-")) {

0 commit comments

Comments
 (0)