summaryrefslogtreecommitdiff
path: root/tests/misc
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2015-06-21 04:04:29 +0100
committerPádraig Brady <P@draigBrady.com>2015-06-22 02:02:05 +0100
commita3c3e1e9e6d2d953692f1eb24efa9ac7c7448044 (patch)
tree511d87148bec56ccc4ea3a3d4006a313fec32439 /tests/misc
parent0a279f619055cc165bb3cfa3bb737cdd28ed4d70 (diff)
downloadcoreutils-a3c3e1e9e6d2d953692f1eb24efa9ac7c7448044.tar.xz
numfmt: avoid integer overflow when rounding
Due to existing limits this is usually triggered with an increased precision. We also add further restrictions to the output of increased precision numbers. * src/numfmt.c (simple_round): Avoid intmax_t overflow. (simple_strtod_int): Count digits consistently for precision loss and overflow detection. (prepare_padded_number): Include the precision when excluding numbers to output, since the precision determines the ultimate values used in the rounding scheme in double_to_human(). * tests/misc/numfmt.pl: Add previously failing test cases. * NEWS: Mention the fix.
Diffstat (limited to 'tests/misc')
-rwxr-xr-xtests/misc/numfmt.pl11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/misc/numfmt.pl b/tests/misc/numfmt.pl
index 4ed1d666d..25bba61b2 100755
--- a/tests/misc/numfmt.pl
+++ b/tests/misc/numfmt.pl
@@ -21,6 +21,8 @@ use strict;
(my $program_name = $0) =~ s|.*/||;
my $prog = 'numfmt';
+my $limits = getlimits ();
+
# TODO: add localization tests with "grouping"
# Turn off localization of executable's output.
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
@@ -534,6 +536,11 @@ my @Tests =
{ERR => "$prog: value too large to be printed: '1e+19' " .
"(consider using --to)\n"},
{EXIT=>2}],
+ ['large-4','1000000000000000000.0',
+ {ERR => "$prog: value/precision too large to be printed: " .
+ "'1e+18/1' (consider using --to)\n"},
+ {EXIT=>2}],
+
# Test input:
# Up to 27 digits is OK.
@@ -648,6 +655,10 @@ my @Tests =
"(cannot handle values > 999Y)\n"},
{EXIT => 2}],
+ # intmax_t overflow when rounding caused this to fail before 8.24
+ ['large-15',$limits->{INTMAX_OFLOW}, {OUT=>$limits->{INTMAX_OFLOW}}],
+ ['large-16','9.300000000000000000', {OUT=>'9.300000000000000000'}],
+
# precision override
['precision-1','--format=%.4f 9991239123 --to=si', {OUT=>"9.9913G"}],
['precision-2','--format=%.1f 9991239123 --to=si', {OUT=>"10.0G"}],