public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: testsuite: libltp: fix warnings showing up with -Wall
Date: Wed,  2 Dec 2020 13:13:24 +0000 (GMT)	[thread overview]
Message-ID: <20201202131324.54E903857805@sourceware.org> (raw)

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

commit 702bec7bc9e903500dcfe9e5a572c35b8bd0fa46
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Wed Dec 2 14:12:24 2020 +0100

    Cygwin: testsuite: libltp: fix warnings showing up with -Wall
    
    This libltp is old as old dirt and still using K&R style.
    If it's really to be used again at all, it needs a serious
    refresh.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/testsuite/libltp/lib/databin.c     |  2 --
 winsup/testsuite/libltp/lib/search_path.c |  5 ++++-
 winsup/testsuite/libltp/lib/tst_tmpdir.c  |  6 +++++-
 winsup/testsuite/libltp/lib/write_log.c   | 18 ++++++++++--------
 4 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/winsup/testsuite/libltp/lib/databin.c b/winsup/testsuite/libltp/lib/databin.c
index f09c2c86c..e43fef4e4 100644
--- a/winsup/testsuite/libltp/lib/databin.c
+++ b/winsup/testsuite/libltp/lib/databin.c
@@ -98,12 +98,10 @@ char **errmsg;
 {
     int cnt;
     unsigned char *chr;
-    int total;
     long expbits;
     long actbits;
 
 	chr=buffer;
-	total=bsize;
 
 	if ( errmsg != NULL ) {
 	    *errmsg = Errmsg;
diff --git a/winsup/testsuite/libltp/lib/search_path.c b/winsup/testsuite/libltp/lib/search_path.c
index 775c7b1a6..697b4037b 100644
--- a/winsup/testsuite/libltp/lib/search_path.c
+++ b/winsup/testsuite/libltp/lib/search_path.c
@@ -50,6 +50,9 @@
 #include <sys/param.h>
 #include <sys/stat.h>
 
+#pragma GCC diagnostic ignored "-Wformat-overflow"
+#pragma GCC diagnostic ignored "-Wformat-truncation"
+
 extern int errno;
 
 struct stat stbuf;
@@ -221,7 +224,7 @@ printf("search_path: res_path = '%s'\n", res_path);
 		toolong++;
 	        continue;
             }
-            sprintf(tmppath, "%s/%s", curpath, res_path);
+            snprintf(tmppath, sizeof tmppath, "%s/%s", curpath, res_path);
 	    strcpy(res_path, tmppath);
 #if DEBUG
 printf("search_path: full res_path= '%s'\n", res_path);
diff --git a/winsup/testsuite/libltp/lib/tst_tmpdir.c b/winsup/testsuite/libltp/lib/tst_tmpdir.c
index cd9d9c8b8..064861e56 100644
--- a/winsup/testsuite/libltp/lib/tst_tmpdir.c
+++ b/winsup/testsuite/libltp/lib/tst_tmpdir.c
@@ -69,6 +69,9 @@
 #include "test.h"
 #include "rmobj.h"
 
+#pragma GCC diagnostic ignored "-Wformat-overflow"
+#pragma GCC diagnostic ignored "-Wformat-truncation"
+
 /*
  * Define some useful macros.
  */
@@ -259,7 +262,8 @@ tst_rmdir()
       if ( getcwd(current_dir,PATH_MAX) == NULL )
          strcpy(parent_dir, TESTDIR);
       else
-         sprintf(parent_dir, "%s/%s", current_dir, TESTDIR);
+         snprintf(parent_dir, sizeof parent_dir,
+		  "%s/%s", current_dir, TESTDIR);
    } else {
       strcpy(parent_dir, TESTDIR);
    }
diff --git a/winsup/testsuite/libltp/lib/write_log.c b/winsup/testsuite/libltp/lib/write_log.c
index 316dfe79b..8104b05ac 100644
--- a/winsup/testsuite/libltp/lib/write_log.c
+++ b/winsup/testsuite/libltp/lib/write_log.c
@@ -90,7 +90,7 @@
 /*#define PATH_MAX pathconf("/", _PC_PATH_MAX)*/
 #endif
 
-char	Wlog_Error_String[256];
+char	Wlog_Error_String[2048];
 
 #if __STDC__
 static int	wlog_rec_pack(struct wlog_rec *wrec, char *buf, int flag);
@@ -137,7 +137,7 @@ int			mode;
 	umask(omask);
 
 	if (wfile->w_afd == -1) {
-		sprintf(Wlog_Error_String,
+		snprintf(Wlog_Error_String, sizeof Wlog_Error_String,
 			"Could not open write_log - open(%s, %#o, %#o) failed:  %s\n",
 			wfile->w_file, oflags, mode, strerror(errno));
 		return -1;
@@ -149,7 +149,7 @@ int			mode;
 
 	oflags = O_RDWR;
 	if ((wfile->w_rfd = open(wfile->w_file, oflags)) == -1) {
-		sprintf(Wlog_Error_String,
+		snprintf(Wlog_Error_String, sizeof Wlog_Error_String,
 			"Could not open write log - open(%s, %#o) failed:  %s\n",
 			wfile->w_file, oflags, strerror(errno));
 		close(wfile->w_afd);
@@ -255,8 +255,9 @@ int 			nrecs;
 int 			(*func)();
 long			data;
 {
-	int			fd, leftover, nbytes, offset, recnum, reclen, rval;
-	char    		buf[BSIZE*32], *bufend, *cp, *bufstart;
+	int		fd, leftover, nbytes, recnum, reclen, rval;
+	off_t		offset;
+	char		buf[BSIZE*32], *bufend, *cp, *bufstart;
 	char		albuf[WLOG_REC_MAX_SIZE];
 	struct wlog_rec	wrec;
 
@@ -295,9 +296,10 @@ long			data;
 		nbytes = read(fd, bufstart, bufend - bufstart - leftover);
 
 		if (nbytes == -1) {
-			sprintf(Wlog_Error_String,
-				"Could not read history file at offset %d - read(%d, %#o, %d) failed:  %s\n",
-				offset, fd, (int)bufstart,
+			snprintf(Wlog_Error_String, sizeof Wlog_Error_String,
+				"Could not read history file at offset %jd - "
+				"read(%d, %#to, %td) failed:  %s\n",
+				(intmax_t)offset, fd, (ptrdiff_t)bufstart,
 				bufend - bufstart - leftover, strerror(errno));
 			return -1;
 		}


                 reply	other threads:[~2020-12-02 13:13 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=20201202131324.54E903857805@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-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).