Debian Codegraph @

t/cpanrt-overflow.t

raw
1 use strict;
2 use warnings;
3 use Test::More tests => 3;
4 use Date::Parse qw(str2time);
5
6 # RT#88777: str2time for far-future dates must not return negative epoch
7 # On 32-bit platforms timegm() overflows for years beyond ~2038, returning
8 # a wrong negative (or wrapping) value. str2time() must detect this and
9 # return undef rather than a nonsense negative epoch.
10 {
11 my @cases = (
12 [ "2900/01/01 00:00:00", "year 2900" ],
13 [ "3000/01/01 00:00:00", "year 3000" ],
14 [ "3870/01/01 00:59:59", "year 3870 (exact RT date)" ],
15 );
16
17 for my $c (@cases) {
18 my ($date, $desc) = @$c;
19 my $t = str2time($date);
20 ok( !defined($t) || $t >= 0,
21 "RT#88777: $desc returns undef or non-negative epoch (got "
22 . ( defined $t ? $t : "undef" ) . ")" );
23 }
24 }