summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-11-08 11:03:58 +0900
committerJunio C Hamano <gitster@pobox.com>2023-11-08 11:03:58 +0900
commit650963cfd060f72e95abf8cec18a3cee9c2a3e1a (patch)
tree56be585bea1436b51fca43369f7cdc1929b41fa1
parent55f95ed8ac8d500f52349927b86f7474138f1ad0 (diff)
parent4815c3c4b26a91301c51360297ebfdef3b96a4ce (diff)
downloadgit-650963cfd060f72e95abf8cec18a3cee9c2a3e1a.tar.gz
Merge branch 'jk/chunk-bounds'
Test portability fix. * jk/chunk-bounds: t: avoid perl's pack/unpack "Q" specifier
-rw-r--r--t/lib-chunk/corrupt-chunk-file.pl30
1 files changed, 27 insertions, 3 deletions
diff --git a/t/lib-chunk/corrupt-chunk-file.pl b/t/lib-chunk/corrupt-chunk-file.pl
index cd6d386fef..0e11aadda8 100644
--- a/t/lib-chunk/corrupt-chunk-file.pl
+++ b/t/lib-chunk/corrupt-chunk-file.pl
@@ -21,6 +21,30 @@ sub copy {
return $buf;
}
+# Some platforms' perl builds don't support 64-bit integers, and hence do not
+# allow packing/unpacking quadwords with "Q". The chunk format uses 64-bit file
+# offsets to support files of any size, but in practice our test suite will
+# only use small files. So we can fake it by asking for two 32-bit values and
+# discarding the first (most significant) one, which is equivalent as long as
+# it's just zero.
+sub unpack_quad {
+ my $bytes = shift;
+ my ($n1, $n2) = unpack("NN", $bytes);
+ die "quad value exceeds 32 bits" if $n1;
+ return $n2;
+}
+sub pack_quad {
+ my $n = shift;
+ my $ret = pack("NN", 0, $n);
+ # double check that our original $n did not exceed the 32-bit limit.
+ # This is presumably impossible on a 32-bit system (which would have
+ # truncated much earlier), but would still alert us on a 64-bit build
+ # of a new test that would fail on a 32-bit build (though we'd
+ # presumably see the die() from unpack_quad() in such a case).
+ die "quad round-trip failed" if unpack_quad($ret) != $n;
+ return $ret;
+}
+
# read until we find table-of-contents entry for chunk;
# note that we cheat a bit by assuming 4-byte alignment and
# that no ToC entry will accidentally look like a header.
@@ -28,7 +52,7 @@ sub copy {
# If we don't find the entry, copy() will hit EOF and exit
# (which should cause the caller to fail the test).
while (copy(4) ne $chunk) { }
-my $offset = unpack("Q>", copy(8));
+my $offset = unpack_quad(copy(8));
# In clear mode, our length will change. So figure out
# the length by comparing to the offset of the next chunk, and
@@ -38,11 +62,11 @@ if ($seek eq "clear") {
my $id;
do {
$id = copy(4);
- my $next = unpack("Q>", get(8));
+ my $next = unpack_quad(get(8));
if (!defined $len) {
$len = $next - $offset;
}
- print pack("Q>", $next - $len + length($bytes));
+ print pack_quad($next - $len + length($bytes));
} while (unpack("N", $id));
}