diff options
author | Pádraig Brady <P@draigBrady.com> | 2012-10-08 15:48:43 +0100 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2012-10-09 00:07:35 +0100 |
commit | 024a1d572c01db2e12a86cd893d98518c73e51d1 (patch) | |
tree | 815f2cc8d0258270310241ddcb43c1bf8198a98b /tests/misc | |
parent | cf9cd8958bbf294c30b82c2d5e9ea64ef14f37b9 (diff) | |
download | coreutils-024a1d572c01db2e12a86cd893d98518c73e51d1.tar.xz |
factor: fix integer validation and GMP fallback
In the recent factor rewrite, the GMP code
wasn't actually used; just an error was printed
on integer overflow. While fixing that it was noticed
that correct input validation wasn't done in all cases
when falling back to the GMP code.
* src/factor.c (print_factors) Fallback to GMP on overflow.
(strto2uintmax): Scan the string for invalid characters,
so that case can be detected independently of overflow.
Return an error when an empty string is passed.
Also allow leading spaces and '+' in input numbers.
* tests/misc/factor.pl: Ensure the GMP code is exercised
when compiled in. Also add a test to verify leading
spaces and '+' are allowed.
Diffstat (limited to 'tests/misc')
-rwxr-xr-x | tests/misc/factor.pl | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/tests/misc/factor.pl b/tests/misc/factor.pl index 38a503714..8f6edaac4 100755 --- a/tests/misc/factor.pl +++ b/tests/misc/factor.pl @@ -28,6 +28,7 @@ my @Tests = ( ['1', '9', {OUT => '3 3'}], ['1a', '7', {OUT => '7'}], + ['1b', ' +7', {OUT => '7'}], ['2', '4294967291', {OUT => '4294967291'}], ['3', '4294967292', {OUT => '2 2 3 3 7 11 31 151 331'}], ['4', '4294967293', {OUT => '9241 464773'}], @@ -74,6 +75,16 @@ my @Tests = ['bug-2012-e', '17754345703', {OUT => '94219 188437'}], ); +# If we have GMP support, append tests to exercise it. +system "grep -w HAVE_GMP $ENV{CONFIG_HEADER} > /dev/null" == 0 + and push (@Tests, + ['bug-gmp-2_sup_128', '340282366920938463463374607431768211456', + {OUT => '2 'x127 . '2'}], + ['bug-gmp-2_sup_256', + '115792089237316195423570985008687907853' + . '269984665640564039457584007913129639936', + {OUT => '2 'x255 . '2'}]); + # Prepend the command line argument and append a newline to end # of each expected 'OUT' string. my $t; @@ -81,7 +92,7 @@ my $t; Test: foreach $t (@Tests) { - my $arg1 = $t->[1]; + (my $arg1 = $t->[1]) =~ s| *\+?||; # Don't fiddle with expected OUT string if there's a nonzero exit status. foreach my $e (@$t) |