On Tue, Dec 13, 2005 at 03:38:46AM -0800, Gisle Aas wrote: > -# check %NNN$ for range bounds, especially negative 2's complement > +# check overflows > +for (int(~0/2+1), ~0, ~0 + 1, ~0 + 2, "9999999999999999999") { ^^^^^^ > + is(eval {sprintf "%${_}d", 0}, undef, "no sprintf result expected > %${_}d");
This fails on my 64-bit system with 'out of memory' errors: $ ./perl -le 'print ~0' 18446744073709551615 $ ./perl -le 'print ~0+2' 1.84467440737096e+19 $ so the format string becomes "%1.84467440737096e+19d", and sprintf tries to do a very large precision %e by accident. > + like($@, qr/^Integer overflow in format string for sprintf /, "overflow > in sprintf"); > + is(eval {printf "%${_}d\n", 0}, undef, "no printf result expected > %${_}d"); > + like($@, qr/^Integer overflow in format string for prtf /, "overflow in > printf"); > +} > > +# check %NNN$ for range bounds > { > my ($warn, $bad) = (0,0); > local $SIG{__WARN__} = sub { > @@ -47,9 +54,10 @@ > $bad++ > } > }; > - my $result = sprintf join('', map("%$_\$s%" . ~$_ . '$s', 1..20)), > - qw(a b c d); > - is($result, "abcd", "only four valid values"); > + > + my $fmt = join('', map("%$_\$s%" . int(~0/2+1-$_) . '$s', 1..20)); > + my $result = sprintf $fmt, qw(a b c d); > + is($result, "abcd", "only four valid values in $fmt"); > is($warn, 36, "expected warnings"); > is($bad, 0, "unexpected warnings"); > } > End of Patch. -- Justice is when you get what you deserve. Law is when you get what you pay for.