luaevent.c: Fix potential overflow in converting seconds to timeval

Thu, 25 Feb 2010 14:50:55 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 25 Feb 2010 14:50:55 +0000
changeset 87
6ff44e01aa5b
parent 86
72cd8cb9b184
child 88
0e346184aa9d

luaevent.c: Fix potential overflow in converting seconds to timeval

src/luaevent.c file | annotate | diff | comparison | revisions
--- a/src/luaevent.c	Mon Feb 15 14:30:27 2010 +0000
+++ b/src/luaevent.c	Thu Feb 25 14:50:55 2010 +0000
@@ -56,8 +56,8 @@
 }
 
 void load_timeval(double time, struct timeval *tv) {
-	tv->tv_sec = (int)time;
-	tv->tv_usec = (int)(time * 1000000) % 1000000;
+	tv->tv_sec = (int) time;
+	tv->tv_usec = (int)( (time - tv->tv_sec) * 1000000 );
 }
 
 /* sock, event, callback, timeout */

mercurial