From d92d3a3c4a7af1ebe56d58c32986ab410f6071ec Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Wed, 31 Aug 2022 15:18:08 -0400 Subject: [PATCH] Fix some Coverity Scan errors. --- newlib/libc/posix/sleep.c | 3 ++- newlib/libc/posix/usleep.c | 1 - newlib/libc/stdio/swscanf.c | 2 ++ newlib/libc/stdio/vswscanf.c | 2 ++ newlib/libc/stdlib/arc4random.c | 2 ++ newlib/libc/time/time.c | 2 ++ 6 files changed, 10 insertions(+), 2 deletions(-) diff --git a/newlib/libc/posix/sleep.c b/newlib/libc/posix/sleep.c index f7c780ef0..0d6cd710d 100644 --- a/newlib/libc/posix/sleep.c +++ b/newlib/libc/posix/sleep.c @@ -7,6 +7,7 @@ #include #include #include +#include unsigned sleep(unsigned seconds) { @@ -15,7 +16,7 @@ unsigned sleep(unsigned seconds) ts.tv_sec = seconds; ts.tv_nsec = 0; if (!nanosleep(&ts,&ts)) return 0; - if (errno == EINTR) return ts.tv_sec; + if (errno == EINTR) return ts.tv_sec & UINT_MAX; return -1; } diff --git a/newlib/libc/posix/usleep.c b/newlib/libc/posix/usleep.c index 9322b6551..cc1b31408 100644 --- a/newlib/libc/posix/usleep.c +++ b/newlib/libc/posix/usleep.c @@ -15,7 +15,6 @@ int usleep(useconds_t useconds) ts.tv_sec = (long int)useconds / 1000000; ts.tv_nsec = ((long int)useconds % 1000000) * 1000; if (!nanosleep(&ts,&ts)) return 0; - if (errno == EINTR) return ts.tv_sec; return -1; } diff --git a/newlib/libc/stdio/swscanf.c b/newlib/libc/stdio/swscanf.c index 5514e68c0..578ac3c93 100644 --- a/newlib/libc/stdio/swscanf.c +++ b/newlib/libc/stdio/swscanf.c @@ -427,6 +427,8 @@ swscanf (const wchar_t *__restrict str, const wchar_t *__restrict fmt, ...) f._read = __seofread; f._ub._base = NULL; f._lb._base = NULL; + f._flags2 = 0; + f._ur = 0; f._file = -1; /* No file. */ va_start (ap, fmt); ret = __ssvfwscanf_r (_REENT, &f, fmt, ap); diff --git a/newlib/libc/stdio/vswscanf.c b/newlib/libc/stdio/vswscanf.c index 13b61f4a3..415c98b0f 100644 --- a/newlib/libc/stdio/vswscanf.c +++ b/newlib/libc/stdio/vswscanf.c @@ -53,6 +53,8 @@ _vswscanf_r (struct _reent *ptr, const wchar_t *str, const wchar_t *fmt, f._read = __seofread; f._ub._base = NULL; f._lb._base = NULL; + f._flags2 = 0; + f._ur = 0; f._file = -1; /* No file. */ return __ssvfwscanf_r (ptr, &f, fmt, ap); } diff --git a/newlib/libc/stdlib/arc4random.c b/newlib/libc/stdlib/arc4random.c index 5860d644a..7bd9e7c5e 100644 --- a/newlib/libc/stdlib/arc4random.c +++ b/newlib/libc/stdlib/arc4random.c @@ -86,6 +86,8 @@ _rs_stir(void) { u_char rnd[KEYSZ + IVSZ]; + memset(rnd, 0, (KEYSZ + IVSZ) * sizeof(u_char)); + if (getentropy(rnd, sizeof rnd) == -1) _getentropy_fail(); diff --git a/newlib/libc/time/time.c b/newlib/libc/time/time.c index 93e061b83..b431f7ae5 100644 --- a/newlib/libc/time/time.c +++ b/newlib/libc/time/time.c @@ -37,6 +37,8 @@ time (time_t * t) { struct timeval now; + now.tv_sec = (time_t) -1; + if (_gettimeofday_r (_REENT, &now, NULL) < 0) now.tv_sec = (time_t) -1; -- 2.43.5