From 0e3294131570837cba068a01ebcea10bdedd67b9 Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Wed, 24 Oct 2012 10:55:13 +0100 Subject: pr: fix -n to pad consistently and not crash * src/pr.c: Replace the code to truncate the most significant digits of line numbers, with much simpler string manipulation that supports arbitrary widths. Before this, specifying a width >= 32 to -n would result in a divide by zero error. Also remove the inconsistent padding with zeros and spaces, which would result in zero padding for widths 12 and 15. * tests/pr/pr-tests.pl: Added a test to ensure no zero padding, and also a test for the divide by zero case. * NEWS: Mentioned the fix Reported by Ondrej Oprala --- tests/pr/pr-tests.pl | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/pr') diff --git a/tests/pr/pr-tests.pl b/tests/pr/pr-tests.pl index d06b34f8f..e648a9953 100755 --- a/tests/pr/pr-tests.pl +++ b/tests/pr/pr-tests.pl @@ -407,6 +407,13 @@ my @tv = ( # Before coreutils-8.13 page numbers were not handled correctly when # headers were not printed (when -l <= 10 or -t or -T specified) ['page-range', '+1:1 -2 -l1 -s" "', "a\nb\nc\n", "a b\n", 0], + +# This padded with zeros before coreutils-8.21 +['padding1', '-t -n,15', "1\n", (" "x 14)."1,1\n", 0], +# This crashed with divide by zero before coreutils-8.21 +['padding2', '-t -n,64', "1\n", (" "x 63)."1,1\n", 0], +# Ensure we handle buffer truncation correctly +['padding3', '-t -N1000000 -n,1', "1\n", "0,1\n", 0], ); # Convert the above old-style test vectors to the newer -- cgit v1.2.3-54-g00ecf