[PATCH] Fixed for a few compiler warnings

Collin Funk <[email protected]>
Newsgroups gmane.comp.gnu.inetutils.bugs
Message-ID <CA+-rG-j2zsNJenA40M8N3NrfL+zjyzFfmLduO0CmLS4twgNcDw@mail.gmail.com>
Hello, I was building inetutils from master and fixed a few simple
compiler warnings. There are more shadowed local variable warnings and
such caused by macro definitions. I can try to fix those in a separate
patch if you'd like.
fix-warnings.patch (text/x-patch, 3.7 KB)
From 8863b07bbb07c69fa0dfca6ca6e3d72f34b70251 Mon Sep 17 00:00:00 2001
From: Collin Funk <[email protected]>
Date: Sun, 7 Jan 2024 12:09:43 -0800
Subject: [PATCH] Fixed for a few compiler warnings.

Fixed shadowed local variables in ftp/ftpd.c, ifconfig/changif.c,
and ifconfig/options.c.
Converted size_t to idx_t to match function declarations in
src/syslogd.c and talkd/process.c.
Avoid declaring environ in telnet/command.c as it is already guaranteed
by gnulib.
Don't bother checking EAGAIN when it is the same value as EAGAIN in
telnetd/utility.c.
---
 ftpd/ftpd.c         | 3 +--
 ifconfig/changeif.c | 3 +--
 ifconfig/options.c  | 2 --
 src/syslogd.c       | 2 +-
 talkd/process.c     | 2 +-
 telnet/commands.c   | 1 -
 telnetd/utility.c   | 2 +-
 7 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/ftpd/ftpd.c b/ftpd/ftpd.c
index 6df4f50a..de58a36b 100644
--- a/ftpd/ftpd.c
+++ b/ftpd/ftpd.c
@@ -969,6 +969,7 @@ void
 retrieve (const char *cmd, const char *name)
 {
   FILE *fin, *dout;
+  char line[BUFSIZ];
   struct stat st;
   int (*closefunc) (FILE *);
   size_t buffer_size = BUFSIZ;	/* Dynamic buffer.  */
@@ -980,8 +981,6 @@ retrieve (const char *cmd, const char *name)
     }
   else
     {
-      char line[BUFSIZ];
-
       snprintf (line, sizeof line, cmd, name);
       name = line;
       fin = ftpd_popen (line, "r"), closefunc = ftpd_pclose;
diff --git a/ifconfig/changeif.c b/ifconfig/changeif.c
index 42f6ea72..1246202c 100644
--- a/ifconfig/changeif.c
+++ b/ifconfig/changeif.c
@@ -247,13 +247,12 @@ set_hwaddr (int sfd, struct ifreq *ifr, char *hwaddr)
 # endif/* ifr_hwaddr */
   int err;
   struct ether_addr *ether;
+  struct ether_addr addr;
   struct sockaddr *sa = (struct sockaddr *) &ifr->ifr_hwaddr;
 
   ether = ether_aton (hwaddr);
   if (!ether)
     {
-      struct ether_addr addr;
-
       err = ether_hostton (hwaddr, &addr);
       if (err)
 	{
diff --git a/ifconfig/options.c b/ifconfig/options.c
index e4a56369..5645703b 100644
--- a/ifconfig/options.c
+++ b/ifconfig/options.c
@@ -675,8 +675,6 @@ parse_cmdline (int argc, char *argv[])
 	error (EXIT_FAILURE, 0, "could not get list of interfaces");
       while (ifnxp->if_index != 0 || ifnxp->if_name != NULL)
 	{
-	  struct ifconfig *ifp;
-
 	  ifs = realloc (ifs, ++nifs * sizeof (struct ifconfig));
 	  if (!ifs)
 	    error (EXIT_FAILURE, errno,
diff --git a/src/syslogd.c b/src/syslogd.c
index 6662e8a0..7db4e3b0 100644
--- a/src/syslogd.c
+++ b/src/syslogd.c
@@ -1621,7 +1621,7 @@ wallmsg (struct filed *f, struct iovec *iov)
   STRUCT_UTMP *utp;
 #if defined UTMP_NAME_FUNCTION || !defined HAVE_GETUTXENT
   STRUCT_UTMP *utmpbuf;
-  size_t utmp_count;
+  idx_t utmp_count;
 #endif /* UTMP_NAME_FUNCTION || !HAVE_GETUTXENT */
   int i;
   char *p;
diff --git a/talkd/process.c b/talkd/process.c
index 510d74f4..ba7b7460 100644
--- a/talkd/process.c
+++ b/talkd/process.c
@@ -196,7 +196,7 @@ find_user (char *name, char *tty)
   STRUCT_UTMP *uptr;
 #ifndef HAVE_GETUTXUSER
   STRUCT_UTMP *utmpbuf;
-  size_t utmp_count;
+  idx_t utmp_count;
 #endif /* HAVE_GETUTXUSER */
   int status;
   struct stat statb;
diff --git a/telnet/commands.c b/telnet/commands.c
index d5a3481d..1e0381a9 100644
--- a/telnet/commands.c
+++ b/telnet/commands.c
@@ -1886,7 +1886,6 @@ env_find (const char *var)
 void
 env_init (void)
 {
-  extern char **environ;
   register char **epp, *cp;
   register struct env_lst *ep;
 #ifndef strchr
diff --git a/telnetd/utility.c b/telnetd/utility.c
index d8ec6f0f..ba8f3a67 100644
--- a/telnetd/utility.c
+++ b/telnetd/utility.c
@@ -385,7 +385,7 @@ pty_read (void)
 {
   pcc = readstream (pty, ptyibuf, BUFSIZ);
   if (pcc < 0 && (errno == EWOULDBLOCK
-#ifdef	EAGAIN
+#if defined EAGAIN && EAGAIN != EWOULDBLOCK
 		  || errno == EAGAIN
 #endif
 		  || errno == EIO))
-- 
2.39.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.