From bf228ee6da7ac6b3b91c61fcf3c902740cc94526 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 25 Nov 2020 22:37:01 +0100 Subject: [PATCH] [pvs] The 'tp' pointer was utilized before it was verified against nullptr. --- src/smpi/internals/smpi_bench.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/smpi/internals/smpi_bench.cpp b/src/smpi/internals/smpi_bench.cpp index 9d8fb0b44e..0c2d89b60e 100644 --- a/src/smpi/internals/smpi_bench.cpp +++ b/src/smpi/internals/smpi_bench.cpp @@ -20,6 +20,7 @@ #ifndef WIN32 #include #endif +#include #include #if HAVE_PAPI @@ -235,15 +236,17 @@ int smpi_gettimeofday(struct timeval* tv, struct timezone* tz) #if _POSIX_TIMERS > 0 int smpi_clock_gettime(clockid_t clk_id, struct timespec* tp) { + if (not tp) { + errno = EFAULT; + return -1; + } if (not smpi_process()) return clock_gettime(clk_id, tp); //there is only one time in SMPI, so clk_id is ignored. smpi_bench_end(); double now = SIMIX_get_clock(); - if (tp) { - tp->tv_sec = static_cast(now); - tp->tv_nsec = static_cast((now - tp->tv_sec) * 1e9); - } + tp->tv_sec = static_cast(now); + tp->tv_nsec = static_cast((now - tp->tv_sec) * 1e9); if (smpi_wtime_sleep > 0) simgrid::s4u::this_actor::sleep_for(smpi_wtime_sleep); smpi_bench_begin(); -- 2.20.1