Skip to content

Commit 2664591

Browse files
committed
Merge branch 'ab/valgrind-fixes' into seen
A bit of test framework fixes with a few fixes to issues found by valgrind. * ab/valgrind-fixes: object-file: fix a unpack_loose_header() regression in 3b6a8db commit-graph.c: don't assume that stat() succeeds log test: skip a failing mkstemp() test under valgrind tests: make RUNTIME_PREFIX compatible with --valgrind
2 parents 16069e2 + 995cfb0 commit 2664591

File tree

7 files changed

+39
-14
lines changed

7 files changed

+39
-14
lines changed

commit-graph.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,7 +2197,8 @@ static void mark_commit_graphs(struct write_commit_graph_context *ctx)
21972197
struct stat st;
21982198
struct utimbuf updated_time;
21992199

2200-
stat(ctx->commit_graph_filenames_before[i], &st);
2200+
if (stat(ctx->commit_graph_filenames_before[i], &st) < 0)
2201+
continue;
22012202

22022203
updated_time.actime = st.st_atime;
22032204
updated_time.modtime = now;
@@ -2238,7 +2239,8 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
22382239
strbuf_setlen(&path, dirnamelen);
22392240
strbuf_addstr(&path, de->d_name);
22402241

2241-
stat(path.buf, &st);
2242+
if (stat(path.buf, &st) < 0)
2243+
continue;
22422244

22432245
if (st.st_mtime > expire_time)
22442246
continue;

object-file.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,8 +2630,12 @@ int read_loose_object(const char *path,
26302630
goto out;
26312631
}
26322632

2633-
if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr),
2634-
NULL) < 0) {
2633+
switch (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr),
2634+
NULL)) {
2635+
case ULHR_OK:
2636+
break;
2637+
case ULHR_BAD:
2638+
case ULHR_TOO_LONG:
26352639
error(_("unable to unpack header of %s"), path);
26362640
goto out;
26372641
}

t/t0060-path-utils.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,15 +542,15 @@ test_lazy_prereq CAN_EXEC_IN_PWD '
542542
./git rev-parse
543543
'
544544

545-
test_expect_success RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'RUNTIME_PREFIX works' '
545+
test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'RUNTIME_PREFIX works' '
546546
mkdir -p pretend/bin pretend/libexec/git-core &&
547547
echo "echo HERE" | write_script pretend/libexec/git-core/git-here &&
548548
cp "$GIT_EXEC_PATH"/git$X pretend/bin/ &&
549549
GIT_EXEC_PATH= ./pretend/bin/git here >actual &&
550550
echo HERE >expect &&
551551
test_cmp expect actual'
552552

553-
test_expect_success RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works' '
553+
test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works' '
554554
mkdir -p pretend/bin &&
555555
cp "$GIT_EXEC_PATH"/git$X pretend/bin/ &&
556556
git config yes.path "%(prefix)/yes" &&

t/t1006-cat-file.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ test_expect_success 'cat-file -t and -s on corrupt loose object' '
681681
682682
# Setup and create the empty blob and its path
683683
empty_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$EMPTY_BLOB")) &&
684-
git hash-object -w --stdin </dev/null &&
684+
empty_blob=$(git hash-object -w --stdin </dev/null) &&
685685
686686
# Create another blob and its path
687687
echo other >other.blob &&
@@ -722,7 +722,13 @@ test_expect_success 'cat-file -t and -s on corrupt loose object' '
722722
# content out as-is. Try to make it zlib-invalid.
723723
mv -f other.blob "$empty_path" &&
724724
test_must_fail git fsck 2>err.fsck &&
725-
grep "^error: inflate: data stream error (" err.fsck
725+
cat >expect <<-EOF &&
726+
error: inflate: data stream error (incorrect header check)
727+
error: unable to unpack header of ./$empty_path
728+
error: $empty_blob: object corrupt or missing: ./$empty_path
729+
EOF
730+
grep "^error: " err.fsck >actual &&
731+
test_cmp expect actual
726732
)
727733
'
728734

t/t1450-fsck.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,10 +774,19 @@ test_expect_success 'fsck finds problems in duplicate loose objects' '
774774
# no "-d" here, so we end up with duplicates
775775
git repack &&
776776
# now corrupt the loose copy
777-
file=$(sha1_file "$(git rev-parse HEAD)") &&
777+
oid="$(git rev-parse HEAD)" &&
778+
file=$(sha1_file "$oid") &&
778779
rm "$file" &&
779780
echo broken >"$file" &&
780-
test_must_fail git fsck
781+
test_must_fail git fsck 2>err &&
782+
783+
cat >expect <<-EOF &&
784+
error: inflate: data stream error (incorrect header check)
785+
error: unable to unpack header of $file
786+
error: $oid: object corrupt or missing: $file
787+
EOF
788+
grep "^error: " err >actual &&
789+
test_cmp expect actual
781790
)
782791
'
783792

t/t4202-log.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,10 +1992,13 @@ test_expect_success GPG 'log --show-signature for merged tag with GPG failure' '
19921992
git tag -s -m signed_tag_msg signed_tag_fail &&
19931993
git checkout plain-fail &&
19941994
git merge --no-ff -m msg signed_tag_fail &&
1995-
TMPDIR="$(pwd)/bogus" git log --show-signature -n1 plain-fail >actual &&
1996-
grep "^merged tag" actual &&
1997-
grep "^No signature" actual &&
1998-
! grep "^gpg: Signature made" actual
1995+
if ! test_have_prereq VALGRIND
1996+
then
1997+
TMPDIR="$(pwd)/bogus" git log --show-signature -n1 plain-fail >actual &&
1998+
grep "^merged tag" actual &&
1999+
grep "^No signature" actual &&
2000+
! grep "^gpg: Signature made" actual
2001+
fi
19992002
'
20002003

20012004
test_expect_success GPGSM 'log --graph --show-signature for merged tag x509' '

t/test-lib.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,7 @@ test -n "$USE_LIBPCRE2" && test_set_prereq PCRE
16671667
test -n "$USE_LIBPCRE2" && test_set_prereq LIBPCRE2
16681668
test -z "$NO_GETTEXT" && test_set_prereq GETTEXT
16691669
test -n "$SANITIZE_LEAK" && test_set_prereq SANITIZE_LEAK
1670+
test -n "$GIT_VALGRIND_ENABLED" && test_set_prereq VALGRIND
16701671

16711672
if test -z "$GIT_TEST_CHECK_CACHE_TREE"
16721673
then

0 commit comments

Comments
 (0)