Skip to content

Commit 8e9a1d0

Browse files
pks-tgitster
authored andcommitted
t/helper: fix segfault in "oid-array" command without repository
The "oid-array" test helper can supposedly work without a Git repository, but will in fact crash because `the_repository->hash_algo` is not initialized. This is because `oid_pos()`, which is used by `oid_array_lookup()`, depends on `the_hash_algo->rawsz`. Ideally, we'd adapt `oid_pos()` to not depend on `the_hash_algo` anymore. That is a bigger untertaking though, so instead we fall back to SHA1 when there is no repository. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fa9e009 commit 8e9a1d0

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

t/helper/test-oid-array.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "test-tool.h"
24
#include "hex.h"
35
#include "oid-array.h"
@@ -17,6 +19,8 @@ int cmd__oid_array(int argc UNUSED, const char **argv UNUSED)
1719
int nongit_ok;
1820

1921
setup_git_directory_gently(&nongit_ok);
22+
if (nongit_ok)
23+
repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
2024

2125
while (strbuf_getline(&line, stdin) != EOF) {
2226
const char *arg;

t/t0064-oid-array.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ echoid () {
1515
done
1616
}
1717

18+
test_expect_success 'without repository' '
19+
cat >expect <<-EOF &&
20+
4444444444444444444444444444444444444444
21+
5555555555555555555555555555555555555555
22+
8888888888888888888888888888888888888888
23+
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
24+
EOF
25+
cat >input <<-EOF &&
26+
append 4444444444444444444444444444444444444444
27+
append 5555555555555555555555555555555555555555
28+
append 8888888888888888888888888888888888888888
29+
append aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
30+
for_each_unique
31+
EOF
32+
nongit test-tool oid-array <input >actual &&
33+
test_cmp expect actual
34+
'
35+
1836
test_expect_success 'ordered enumeration' '
1937
echoid "" 44 55 88 aa >expect &&
2038
{

0 commit comments

Comments
 (0)