summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-08 12:59:21 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-08 12:59:21 +0000
commitfef170e87c7e49db5f6c6eab7bcd1b12697c7e7f (patch)
tree0e92684322f95ce683600a0069e3c6569ec4b93c /time.c
parent685597fdc1ed01ceafae840870ba455037812dad (diff)
* time.c (time_overflow_p): Avoid signed integer overflow.
(rb_time_new): Fix overflow condition. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/time.c b/time.c
index 51d7581e01..20476e9343 100644
--- a/time.c
+++ b/time.c
@@ -2226,16 +2226,16 @@ time_overflow_p(time_t *secp, long *nsecp)
if (TIMET_MAX - sec2 < sec) {
rb_raise(rb_eRangeError, "out of Time range");
}
- nsec %= 1000000000;
+ nsec -= sec2 * 1000000000;
sec += sec2;
}
- if (nsec < 0) { /* nsec negative overflow */
+ else if (nsec < 0) { /* nsec negative overflow */
sec2 = NDIV(nsec,1000000000); /* negative div */
if (sec < TIMET_MIN - sec2) {
rb_raise(rb_eRangeError, "out of Time range");
}
- nsec = NMOD(nsec,1000000000); /* negative mod */
- sec = sec + sec2;
+ nsec -= sec2 * 1000000000;
+ sec += sec2;
}
#ifndef NEGATIVE_TIME_T
if (sec < 0)
@@ -2281,9 +2281,9 @@ rb_time_new(time_t sec, long usec)
usec -= sec2 * 1000000;
sec += sec2;
}
- else if (usec <= 1000000) {
- long sec2 = usec / 1000000;
- if (sec < -TIMET_MAX - sec2) {
+ else if (usec < 0) {
+ long sec2 = NDIV(usec,1000000); /* negative div */
+ if (sec < TIMET_MIN - sec2) {
rb_raise(rb_eRangeError, "out of Time range");
}
usec -= sec2 * 1000000;