summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-02 18:43:23 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-02 18:43:23 (GMT)
commit0989529f88efc0882fd5f567350d196664bf8318 (patch)
tree43f1eeb20d66e6957ed4695d8d23c4c69ca0291a /time.c
parent9621f8a9ac55aea12312c1afd1efdc24e3b9944b (diff)
time.c: fix underflow of unsigned integers
* time.c (vtm_add_offset): get rid of underflow of unsigned integers. fix up r45155. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/time.c b/time.c
index fcf5717..43ae533 100644
--- a/time.c
+++ b/time.c
@@ -1997,37 +1997,40 @@ vtm_add_offset(struct vtm *vtm, VALUE off)
not_zero_sec:
/* If sec + subsec == 0, don't change vtm->sec.
* It may be 60 which is a leap second. */
- vtm->sec += sec;
- if (vtm->sec < 0) {
- vtm->sec += 60;
+ sec += vtm->sec;
+ if (sec < 0) {
+ sec += 60;
min -= 1;
}
- if (60 <= vtm->sec) {
- vtm->sec -= 60;
+ if (60 <= sec) {
+ sec -= 60;
min += 1;
}
+ vtm->sec = sec;
}
if (min) {
- vtm->min += min;
- if (vtm->min < 0) {
- vtm->min += 60;
+ min += vtm->min;
+ if (min < 0) {
+ min += 60;
hour -= 1;
}
- if (60 <= vtm->min) {
- vtm->min -= 60;
+ if (60 <= min) {
+ min -= 60;
hour += 1;
}
+ vtm->min = min;
}
if (hour) {
- vtm->hour += hour;
- if (vtm->hour < 0) {
- vtm->hour += 24;
+ hour += vtm->hour;
+ if (hour < 0) {
+ hour += 24;
day = -1;
}
- if (24 <= vtm->hour) {
- vtm->hour -= 24;
+ if (24 <= hour) {
+ hour -= 24;
day = 1;
}
+ vtm->hour = hour;
}
if (day) {