summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul \"LeoNerd\" Evans <leonerd@leonerd.org.uk>2011-12-23 18:08:19 +0000
committerÆvar Arnfjörð Bjarmason <avar@cpan.org>2011-12-23 18:38:54 +0000
commit73373ca8b0bb075491bc8c43f96b557794d330f4 (patch)
tree348419759ba2712032056cb62833d44851ae34b5
parentc5a3a120d2e6afcd8643d09772819cd1f0e53051 (diff)
downloadperl-73373ca8b0bb075491bc8c43f96b557794d330f4.tar.gz
Only have strptime() call mktime() if mday/mon/year are all valid
-rw-r--r--ext/POSIX/POSIX.xs3
-rw-r--r--ext/POSIX/t/time.t5
2 files changed, 6 insertions, 2 deletions
diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs
index b37f19e196..89e625365e 100644
--- a/ext/POSIX/POSIX.xs
+++ b/ext/POSIX/POSIX.xs
@@ -1888,7 +1888,8 @@ strptime(str, fmt, sec=-1, min=-1, hour=-1, mday=-1, mon=-1, year=-1, wday=-1, y
posmg->mg_len = remains - str_base;
}
- mktime(&tm);
+ if(tm.tm_mday > -1 && tm.tm_mon > -1 && tm.tm_year > -1)
+ mktime(&tm);
EXTEND(SP, 9);
PUSHs(sv_2mortal(newSViv(tm.tm_sec)));
diff --git a/ext/POSIX/t/time.t b/ext/POSIX/t/time.t
index 577c4554a0..15605bf991 100644
--- a/ext/POSIX/t/time.t
+++ b/ext/POSIX/t/time.t
@@ -4,7 +4,7 @@ use strict;
use Config;
use POSIX;
-use Test::More tests => 27;
+use Test::More tests => 28;
# go to UTC to avoid DST issues around the world when testing. SUS3 says that
# null should get you UTC, but some environments want the explicit names.
@@ -77,6 +77,9 @@ is_deeply(\@time, [1, 23, 4, 18, 12-1, 2011-1900, 0, 351, 0], 'strptime() all da
@time = POSIX::strptime("12:34:56", "%H:%M:%S", 1, 2, 3, 4, 5, 6);
is_deeply(\@time, [56, 34, 12, 4, 5, 6, 1, 154, 0], 'strptime() all date fields with passed time');
+@time = POSIX::strptime("July 4", "%b %d");
+is_deeply([@time[3,4]], [4, 7-1], 'strptime() partial yields correct mday/mon');
+
@time = POSIX::strptime("Foobar", "%H:%M:%S");
is(scalar @time, 0, 'strptime() invalid input yields empty list');