public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jeff Johnston <jjohnstn@sourceware.org>
To: newlib-cvs@sourceware.org
Subject: [newlib-cygwin] Fix some Coverity Scan errors.
Date: Wed, 31 Aug 2022 19:19:21 +0000 (GMT)	[thread overview]
Message-ID: <20220831191921.593C93858428@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=d92d3a3c4a7af1ebe56d58c32986ab410f6071ec

commit d92d3a3c4a7af1ebe56d58c32986ab410f6071ec
Author: Jeff Johnston <jjohnstn@redhat.com>
Date:   Wed Aug 31 15:18:08 2022 -0400

    Fix some Coverity Scan errors.

Diff:
---
 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 <errno.h>
 #include <time.h>
 #include <unistd.h>
+#include <limits.h>
 
 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;

                 reply	other threads:[~2022-08-31 19:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220831191921.593C93858428@sourceware.org \
    --to=jjohnstn@sourceware.org \
    --cc=newlib-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).