# Integer overflow on struct timespec

**URL:** <https://www.ruby-forum.com/t/integer-overflow-on-struct-timespec/124569>\
**Category:** Development\
**Created:** [December 30, 2007, 10:33am UTC](https://www.ruby-forum.com/t/integer-overflow-on-struct-timespec/124569 "2007-12-30T10:33:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zunda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/8797f3/32.png) [@zunda](https://www.ruby-forum.com/u/zunda)\
**Post date:** [December 30, 2007, 10:33am UTC](https://www.ruby-forum.com/t/integer-overflow-on-struct-timespec/124569/1 "2007-12-30T10:33:22Z")

</div>

zundae$B$H?=$7$^$9e(B

e$B?H6a$K!"e(Bstruct  
timespece$B$Ne(Btv\_sece$B$,e(B4e$B%P%$%H$G!“e(Bstruct timevale$B$Ne(B  
tv\_sece$B$,e(B8e$B%P%$%H$N%7%9%F%`$,$”$j$^$9!#$3$N$h$&$J4D6-$G$Oe(B  
ruby-1.9.0-0e$B$Ne(B make  
teste$B$,e(Btest\_thread.rbe$B$G\<:GT$7$^$9!#e(B(e$B\>:Y$Oe(B  
[http://zunda.freeshell.org/d/20071227.html#p02](http://zunda.freeshell.org/d/20071227.html#p02) e$B$r$4Mw$/$@$5$$e(B)  
e$B\<:GT$O2\<5-$N$h$&$J%3!\<%I$G$b:F8=$G$-$^$9!#e(B

$ uname -srm  
NetBSD 3.0.2\_PATCH alpha  
$ rm -f thread.o  
$ make cflags=-DTHREAD\_DEBUG miniruby  
$ ./miniruby -e ‘Thread.new{}.join(1000000000)’  
0x1ffe00000 - create: 0x1203a5800 (0)0x1ffe00000 - thread\_join (thid:  
0x162e00000)  
0x1ffe00000 - native\_sleep 999999999  
0x1ffe00000 - native\_sleep: pthread\_cond\_timedwait start (-2096164855,  
18650000)  
miniruby: Error detected by libpthread: Invalid wait time.  
Detected by file  
“/home/builds/ab/netbsd-3-1-RELEASE/src/lib/libpthread/pthread\_cond.c”,  
line 186,  
function “pthread\_cond\_timedwait”.  
See pthread(3) for information.  
Abort trap

e$B$3$N%(%i!\<$N860x$O!"e(Bthread\_pthread.ce$B$Ne(B412e$B9TL$NB-$7;;e(B(e$B:8JU$,e(B  
struct timespece$B!"1&JU$Oe(B2e$B$D$H$be(Bsruct timeval)  
ts.tv\_sec = tvn.tv\_sec + tv-\>tv\_sec;  
e$B$,%\*!\<%P!\<%U%m!\<$7$F$$$k$?$a$H;W$$$^$9!#\<j85$G$O2\<5-$N%Q%C%A$Ge(B  
make teste$B$,@.8y$9$k$h$&$K$J$j$^$7$?!#e(B

# Index: thread\_pthread.c

— thread\_pthread.c (revision 14793)  
+++ thread\_pthread.c (working copy)  
@@ -432,7 +432,7 @@  
thread\_debug(“native\_sleep: interrupted before sleep\n”);  
}  
else {

- 

```
 if (tv == 0) {

```

- 

```
 if (tv == 0 || ts.tv_sec < tvn.tv_sec /* overflow */ ) {

```

thread\_debug(“native\_sleep: pthread\_cond\_wait start\n”);  
pthread\_cond\_wait(&th-\>native\_thread\_data.sleep\_cond,  
&th-\>interrupt\_lock);

e$BI,MW$G$7$?$i=$@5$r$\*4j$$$7$^$9!#e(B
