Skip to content

Commit cc61cf4

Browse files
peffgitster
authored andcommitted
test-ref-store: avoid passing NULL to printf
It's possible for resolve_ref_unsafe() to return NULL (e.g., if we are reading and the ref does not exist), in which case we'll pass NULL to printf. On glibc systems this produces "(null)", but on others it may segfault. The tests don't expect any such case, but if we ever did trigger this, we would prefer to cleanly fail the test with unexpected input rather than segfault. Let's manually replace NULL with "(null)". The exact value doesn't matter, as it won't match any possible ref the caller could expect (and anyway, the exit code of the program will tell whether "ref" is valid or not). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4843cde commit cc61cf4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

t/helper/test-ref-store.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static int cmd_resolve_ref(struct ref_store *refs, const char **argv)
135135

136136
ref = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
137137
sha1, &flags);
138-
printf("%s %s 0x%x\n", sha1_to_hex(sha1), ref, flags);
138+
printf("%s %s 0x%x\n", sha1_to_hex(sha1), ref ? ref : "(null)", flags);
139139
return ref ? 0 : 1;
140140
}
141141

0 commit comments

Comments
 (0)