Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix: fix integer overflow in uv_hrtime
Browse files Browse the repository at this point in the history
Conversion to nanoseconds was overflowing with 32-bit builds.
  • Loading branch information
timholy authored and piscisaureus committed Aug 18, 2012
1 parent 22ce5a3 commit ce87b7e
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/unix/cygwin.c
Expand Up @@ -35,7 +35,7 @@
uint64_t uv_hrtime() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (ts.tv_sec * NANOSEC + ts.tv_nsec);
return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
}

void uv_loadavg(double avg[3]) {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/freebsd.c
Expand Up @@ -57,7 +57,7 @@ static char *process_title;
uint64_t uv_hrtime(void) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (ts.tv_sec * NANOSEC + ts.tv_nsec);
return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
}


Expand Down
2 changes: 1 addition & 1 deletion src/unix/linux/linux-core.c
Expand Up @@ -71,7 +71,7 @@ static struct {
uint64_t uv_hrtime() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (ts.tv_sec * NANOSEC + ts.tv_nsec);
return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
}


Expand Down
2 changes: 1 addition & 1 deletion src/unix/netbsd.c
Expand Up @@ -38,7 +38,7 @@
uint64_t uv_hrtime(void) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (ts.tv_sec * NANOSEC + ts.tv_nsec);
return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
}

void uv_loadavg(double avg[3]) {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/openbsd.c
Expand Up @@ -46,7 +46,7 @@ static char *process_title;
uint64_t uv_hrtime(void) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (ts.tv_sec * NANOSEC + ts.tv_nsec);
return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
}


Expand Down

0 comments on commit ce87b7e

Please sign in to comment.