* [PATCH v2] t8002: fix ambiguous printf conversion specifications
@ 2025-01-20 11:41 Jan Palus
2025-01-21 22:10 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: Jan Palus @ 2025-01-20 11:41 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Jan Palus, Patrick Steinhardt
In e7fb2ca945 (builtin/blame: fix out-of-bounds write with blank
boundary commits, 2025-01-10), we have introduced two new tests that
expect a certain amount of padding. This padding is generated via
printf using the "%0.s" conversion specification. That directive is
ambiguous because it might be interpreted as field width (most shells)
or 0-padding flag for numeric fields (coreutils).
Fix this issue by using "%${N}s" instead, which is already being
used in other tests (i.e. t5300, t0450) and is unambiguous.
Helped-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Jan Palus <jpalus@fastmail.com>
---
t/t8002-blame.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh
index 1ad039e123..e98993276a 100755
--- a/t/t8002-blame.sh
+++ b/t/t8002-blame.sh
@@ -138,7 +138,7 @@ test_expect_success 'blame --abbrev -b truncates the blank boundary' '
# Note that `--abbrev=` always gets incremented by 1, which is why we
# expect 11 leading spaces and not 10.
cat >expect <<-EOF &&
- $(printf "%0.s " $(test_seq 11)) (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
+ $(printf "%11s" "") (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
EOF
git blame -b --abbrev=10 ^HEAD -- abbrev.t >actual &&
test_cmp expect actual
@@ -146,7 +146,7 @@ test_expect_success 'blame --abbrev -b truncates the blank boundary' '
test_expect_success 'blame with excessive --abbrev and -b culls to hash length' '
cat >expect <<-EOF &&
- $(printf "%0.s " $(test_seq $hexsz)) (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
+ $(printf "%${hexsz}s" "") (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
EOF
git blame -b --abbrev=9000 ^HEAD -- abbrev.t >actual &&
test_cmp expect actual
--
2.48.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] t8002: fix ambiguous printf conversion specifications
2025-01-20 11:41 [PATCH v2] t8002: fix ambiguous printf conversion specifications Jan Palus
@ 2025-01-21 22:10 ` Junio C Hamano
0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2025-01-21 22:10 UTC (permalink / raw)
To: Jan Palus; +Cc: git, Patrick Steinhardt
Jan Palus <jpalus@fastmail.com> writes:
> - $(printf "%0.s " $(test_seq 11)) (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
> + $(printf "%11s" "") (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
This obviously is much clearer than the obscure original that
concatenates " " 11 times (for 11 arguments that printf receives).
Nice.
> @@ -146,7 +146,7 @@ test_expect_success 'blame --abbrev -b truncates the blank boundary' '
>
> test_expect_success 'blame with excessive --abbrev and -b culls to hash length' '
> cat >expect <<-EOF &&
> - $(printf "%0.s " $(test_seq $hexsz)) (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
> + $(printf "%${hexsz}s" "") (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
The fact that $hexsz was not quoted in the original made me look at
how it is defined (as an unquoted variable reference is often a way
to lose unwanted leading whitespaces, e.g. bytes=$(wc -c <foo) &&
show $bytes), but it seems that hexsz would not get any leading (or
trailing) whitespaces so this rewrite perfectly fine.
Thanks. Will queue.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-01-21 22:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-20 11:41 [PATCH v2] t8002: fix ambiguous printf conversion specifications Jan Palus
2025-01-21 22:10 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).