From 43d8a4eab0294ecd95834627d20f23030fea7e8d Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Fri, 2 Mar 2018 08:59:45 -0500 Subject: [PATCH] Range check minutes under parse --- include/date/date.h | 3 +- test/date_test/parse.pass.cpp | 54 +++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/include/date/date.h b/include/date/date.h index bcd764d..c53bf34 100644 --- a/include/date/date.h +++ b/include/date/date.h @@ -7006,7 +7006,8 @@ from_stream(std::basic_istream& is, const CharT* fmt, goto broken; } fds.ymd = ymd; - fds.tod = time_of_day(hours{h} + minutes{min}); + fds.tod = time_of_day{h}; + fds.tod.m_ = min; fds.tod.s_ = detail::decimal_format_seconds{s}; if (wd != not_a_weekday) fds.wd = weekday{static_cast(wd)}; diff --git a/test/date_test/parse.pass.cpp b/test/date_test/parse.pass.cpp index 6db370d..cad577e 100644 --- a/test/date_test/parse.pass.cpp +++ b/test/date_test/parse.pass.cpp @@ -360,6 +360,12 @@ test_d() assert(!in.bad()); assert(tp == 2016_y/12/9); } + { + std::istringstream in{"2016 31 11"}; + sys_days tp; + in >> parse("%Y %e %m", tp); + assert(in.fail()); + } } void @@ -413,6 +419,12 @@ test_H() assert(!in.bad()); assert(tp == sys_days{2016_y/12/11} + hours{15}); } + { + std::istringstream in{"2016-12-11 24"}; + sys_time tp; + in >> parse("%F %H", tp); + assert(in.fail()); + } } void @@ -436,6 +448,12 @@ test_Ip() assert(!in.bad()); assert(tp == sys_days{2016_y/12/11} + hours{1}); } + { + std::istringstream in{"2016-12-11 13 am"}; + sys_time tp; + in >> parse("%F %I %p", tp); + assert(in.fail()); + } } void @@ -474,6 +492,12 @@ test_m() assert(!in.bad()); assert(tp == 2016_y/9/12); } + { + std::istringstream in{"2016 12 13"}; + sys_days tp; + in >> parse("%Y %d %m", tp); + assert(in.fail()); + } } void @@ -489,6 +513,12 @@ test_M() assert(!in.bad()); assert(tp == sys_days{2016_y/12/11} + minutes{15}); } + { + std::istringstream in{"2016-12-11 65"}; + sys_time tp; + in >> parse("%F %M", tp); + assert(in.fail()); + } } void @@ -512,6 +542,12 @@ test_S() assert(!in.bad()); assert(tp == sys_days{2016_y/12/11} + seconds{15} + milliseconds{1}); } + { + std::istringstream in{"2016-12-11 60"}; + sys_seconds tp; + in >> parse("%F %S", tp); + assert(in.fail()); + } } void @@ -552,6 +588,24 @@ test_T() assert(!in.bad()); assert(d == hours{15} + minutes{43} + seconds{22} + milliseconds{1}); } + { + std::istringstream in{"2016-12-11 24:43:22"}; + sys_seconds tp; + in >> parse("%F %T", tp); + assert(in.fail()); + } + { + std::istringstream in{"2016-12-11 15:60:22"}; + sys_seconds tp; + in >> parse("%F %T", tp); + assert(in.fail()); + } + { + std::istringstream in{"2016-12-11 15:43:60"}; + sys_seconds tp; + in >> parse("%F %T", tp); + assert(in.fail()); + } } void