diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-25 16:23:18 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-25 16:23:18 +0000 |
commit | 2c652768a878dd951385f48df450b2a1dc12dc12 (patch) | |
tree | bb097450bdec4c7127960028b9758db7ed0c31c9 /time.c | |
parent | dd7825791998cec788896b1afb4e87f46dc56440 (diff) | |
download | bundler-2c652768a878dd951385f48df450b2a1dc12dc12.tar.gz |
Normalize month-mday before finding epoch
Especially over the year 2038, 30 Feb and so on may cause odd behavior
on validating found epoch with given year-month-day [Bug #15340]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65974 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r-- | time.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -2876,6 +2876,29 @@ time_arg(int argc, const VALUE *argv, struct vtm *vtm) vtm->mday = obj2ubits(v[2], 5); } + /* normalize month-mday */ + switch (vtm->mon) { + case 2: + { + /* this drops higher bits but it's not a problem to calc leap year */ + unsigned int mday2 = leap_year_v_p(vtm->year) ? 29 : 28; + if (vtm->mday > mday2) { + vtm->mday -= mday2; + vtm->mon++; + } + } + break; + case 4: + case 6: + case 9: + case 11: + if (vtm->mday == 31) { + vtm->mon++; + vtm->mday = 1; + } + break; + } + vtm->hour = NIL_P(v[3])?0:obj2ubits(v[3], 5); vtm->min = NIL_P(v[4])?0:obj2ubits(v[4], 6); |