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

Commit

Permalink
Browse files Browse the repository at this point in the history
unix: fix integer overflow in uv_hrtime
Conversion to nanoseconds was overflowing with 32-bit builds.
  • Loading branch information
piscisaureus committed Aug 18, 2012
1 parent d6a96de commit 0233b92
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 @@ -34,7 +34,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 @@ -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);
}


Expand Down
2 changes: 1 addition & 1 deletion src/unix/linux.c
Expand Up @@ -134,7 +134,7 @@ static char* basename_r(const char* path) {
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/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 @@ -36,7 +36,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

0 comments on commit 0233b92

Please sign in to comment.