From be2ddacb906939d989a422e5b44f121bcf720f0d Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 1 Feb 2023 22:10:36 +0100 Subject: [PATCH] unix: abort on clock_gettime() error (#3898) Per standard libuv operating procedures, abort on unexpected failure. Don't silently ignore the error and return garbage. --- src/unix/posix-hrtime.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/unix/posix-hrtime.c b/src/unix/posix-hrtime.c index 323dfc20392..7b45c01a4d0 100644 --- a/src/unix/posix-hrtime.c +++ b/src/unix/posix-hrtime.c @@ -23,13 +23,14 @@ #include "internal.h" #include +#include #include -#undef NANOSEC -#define NANOSEC ((uint64_t) 1e9) - uint64_t uv__hrtime(uv_clocktype_t type) { - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); + struct timespec t; + + if (clock_gettime(CLOCK_MONOTONIC, &t)) + abort(); + + return t.tv_sec * (uint64_t) 1e9 + t.tv_nsec; }