mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* time.c (time_overflow_p): Avoid signed integer overflow.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42445 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2391ee2c61
commit
319dc9f6c6
2 changed files with 14 additions and 9 deletions
|
@ -1,3 +1,7 @@
|
|||
Thu Aug 8 21:10:05 2013 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* time.c (time_overflow_p): Avoid signed integer overflow.
|
||||
|
||||
Thu Aug 8 19:58:02 2013 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* thread.c (rb_threadptr_pending_interrupt_check_mask):
|
||||
|
|
19
time.c
19
time.c
|
@ -2217,24 +2217,25 @@ time_init(int argc, VALUE *argv, VALUE time)
|
|||
static void
|
||||
time_overflow_p(time_t *secp, long *nsecp)
|
||||
{
|
||||
time_t tmp, sec = *secp;
|
||||
time_t sec = *secp;
|
||||
long nsec = *nsecp;
|
||||
long sec2;
|
||||
|
||||
if (nsec >= 1000000000) { /* nsec positive overflow */
|
||||
tmp = sec + nsec / 1000000000;
|
||||
nsec %= 1000000000;
|
||||
if (sec > 0 && tmp < 0) {
|
||||
sec2 = nsec / 1000000000;
|
||||
if (TIMET_MAX - sec2 < sec) {
|
||||
rb_raise(rb_eRangeError, "out of Time range");
|
||||
}
|
||||
sec = tmp;
|
||||
nsec %= 1000000000;
|
||||
sec += sec2;
|
||||
}
|
||||
if (nsec < 0) { /* nsec negative overflow */
|
||||
tmp = sec + NDIV(nsec,1000000000); /* negative div */
|
||||
nsec = NMOD(nsec,1000000000); /* negative mod */
|
||||
if (sec < 0 && tmp > 0) {
|
||||
sec2 = NDIV(nsec,1000000000); /* negative div */
|
||||
if (sec < TIMET_MAX - sec2) {
|
||||
rb_raise(rb_eRangeError, "out of Time range");
|
||||
}
|
||||
sec = tmp;
|
||||
nsec = NMOD(nsec,1000000000); /* negative mod */
|
||||
sec = sec + sec2;
|
||||
}
|
||||
#ifndef NEGATIVE_TIME_T
|
||||
if (sec < 0)
|
||||
|
|
Loading…
Add table
Reference in a new issue