From: Tony Cook Date: Tue, 23 Feb 2010 13:35:35 +0000 (+1100) Subject: use the correct format codes in warnings from gmtime/localtime X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7eb4f9b7b5bb8d1dc09764c85ca57bc61f5b6f92;p=p5sagit%2Fp5-mst-13.2.git use the correct format codes in warnings from gmtime/localtime --- diff --git a/pp_sys.c b/pp_sys.c index f57bd1a..1fe2ea9 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -4505,22 +4505,22 @@ PP(pp_gmtime) when = (Time64_T)now; } else { - double input = Perl_floor(POPn); + NV input = Perl_floor(POPn); when = (Time64_T)input; if (when != input) { Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW), - "%s(%.0f) too large", opname, input); + "%s(%.0" NVff ") too large", opname, input); } } if ( TIME_LOWER_BOUND > when ) { Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW), - "%s(%.0f) too small", opname, when); + "%s(%.0" NVff ") too small", opname, when); err = NULL; } else if( when > TIME_UPPER_BOUND ) { Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW), - "%s(%.0f) too large", opname, when); + "%s(%.0" NVff ") too large", opname, when); err = NULL; } else { @@ -4533,7 +4533,7 @@ PP(pp_gmtime) if (err == NULL) { /* XXX %lld broken for quads */ Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW), - "%s(%.0f) failed", opname, (double)when); + "%s(%.0" NVff ") failed", opname, when); } if (GIMME != G_ARRAY) { /* scalar context */ diff --git a/t/op/time.t b/t/op/time.t index 84eaf75..7db8ee8 100644 --- a/t/op/time.t +++ b/t/op/time.t @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; } -plan tests => 62; +plan tests => 66; # These tests make sure, among other things, that we don't end up # burning tons of CPU for dates far in the future. @@ -200,3 +200,44 @@ ok(gmtime() =~ /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[ ] $date = localtime($small_time); like $warning, qr/^localtime(.*) too small/; } + +SKIP: { #rt #73040 + # these are from the definitions of TIME_LOWER_BOUND AND TIME_UPPER_BOUND + my $smallest = -67768100567755200.0; + my $biggest = 67767976233316800.0; + + # offset to a value that will fail + my $small_time = $smallest - 200; + my $big_time = $biggest + 200; + + # check they're representable - typically means NV is + # long double + if ($small_time + 200 != $smallest + || $small_time == $smallest + || $big_time - 200 != $biggest + || $big_time == $biggest) { + skip "Can't represent test values", 4; + } + my $small_time_f = sprintf("%.0f", $small_time); + my $big_time_f = sprintf("%.0f", $big_time); + + # check the numbers in the warning are correct + my $warning; + local $SIG{__WARN__} = sub { $warning .= join "\n", @_; }; + $warning = ''; + my $date = gmtime($big_time); + like $warning, qr/^gmtime\($big_time_f\) too large/; + + $warning = ''; + $date = localtime($big_time); + like $warning, qr/^localtime\($big_time_f\) too large/; + + $warning = ''; + $date = gmtime($small_time); + like $warning, qr/^gmtime\($small_time_f\) too small/; + + $warning = ''; + $date = localtime($small_time); + like $warning, qr/^localtime\($small_time_f\) too small/; + +}