Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/inetd inetd: raise WARNS from 5 to 6



details:   https://anonhg.NetBSD.org/src/rev/2b46618b2d98
branches:  trunk
changeset: 985564:2b46618b2d98
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Aug 30 18:21:11 2021 +0000

description:
inetd: raise WARNS from 5 to 6

The necessary fixes include:
* explicit integer conversions, to get rid of mixed signedness
* function prototypes for parameterless functions

While here:
* add space after comma
* add space after 'if'
* place the '{' of a function definition on a separate line
* rename variables 'bits' and 'temp' to 'hi' and 'lo'
* in parse_quote, prefer expressions over assignments
* make hex_to_bits static

No functional change.

diffstat:

 usr.sbin/inetd/Makefile   |   3 ++-
 usr.sbin/inetd/inetd.c    |  38 ++++++++++++++++++++------------------
 usr.sbin/inetd/parse_v2.c |  24 +++++++++++-------------
 3 files changed, 33 insertions(+), 32 deletions(-)

diffs (262 lines):

diff -r 4cfe0e1922a0 -r 2b46618b2d98 usr.sbin/inetd/Makefile
--- a/usr.sbin/inetd/Makefile   Mon Aug 30 18:03:52 2021 +0000
+++ b/usr.sbin/inetd/Makefile   Mon Aug 30 18:21:11 2021 +0000
@@ -1,5 +1,5 @@
 #      from: @(#)Makefile      8.1 (Berkeley) 6/6/93
-#      $NetBSD: Makefile,v 1.27 2021/08/29 11:43:48 christos Exp $
+#      $NetBSD: Makefile,v 1.28 2021/08/30 18:21:11 rillig Exp $
 
 .include <bsd.own.mk>
 
@@ -9,6 +9,7 @@
 SRCS=  inetd.c parse_v2.c
 MAN=   inetd.8
 MLINKS=        inetd.8 inetd.conf.5
+WARNS= 6
 
 # Enables debug printouts when in debug mode
 CPPFLAGS+=-DDEBUG_ENABLE
diff -r 4cfe0e1922a0 -r 2b46618b2d98 usr.sbin/inetd/inetd.c
--- a/usr.sbin/inetd/inetd.c    Mon Aug 30 18:03:52 2021 +0000
+++ b/usr.sbin/inetd/inetd.c    Mon Aug 30 18:21:11 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: inetd.c,v 1.130 2021/08/30 17:32:23 rillig Exp $       */
+/*     $NetBSD: inetd.c,v 1.131 2021/08/30 18:21:11 rillig Exp $       */
 
 /*-
  * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
 #if 0
 static char sccsid[] = "@(#)inetd.c    8.4 (Berkeley) 4/13/94";
 #else
-__RCSID("$NetBSD: inetd.c,v 1.130 2021/08/30 17:32:23 rillig Exp $");
+__RCSID("$NetBSD: inetd.c,v 1.131 2021/08/30 18:21:11 rillig Exp $");
 #endif
 #endif /* not lint */
 
@@ -801,7 +801,7 @@
                        strlcpy(sep->se_ctrladdr_un.sun_path,
                            sep->se_service, n + 1);
                        sep->se_ctrladdr_un.sun_family = AF_LOCAL;
-                       sep->se_ctrladdr_size = (int)(n +
+                       sep->se_ctrladdr_size = (socklen_t)(n +
                            sizeof(sep->se_ctrladdr_un) -
                            sizeof(sep->se_ctrladdr_un.sun_path));
                        if (!ISMUX(sep))
@@ -1825,12 +1825,12 @@
 
        for (i = 0; i <= 128; ++i)
                if (isprint(i))
-                       *endring++ = i;
+                       *endring++ = (char)i;
 }
 
 /* ARGSUSED */
 static void
-chargen_stream(int s,struct servtab *sep)      /* Character generator */
+chargen_stream(int s, struct servtab *sep)     /* Character generator */
 {
        size_t len;
        char *rs, text[LINESIZ+2];
@@ -1845,7 +1845,7 @@
        text[LINESIZ] = '\r';
        text[LINESIZ + 1] = '\n';
        for (rs = ring;;) {
-               if ((len = endring - rs) >= LINESIZ)
+               if ((len = (size_t)(endring - rs)) >= LINESIZ)
                        memmove(text, rs, LINESIZ);
                else {
                        memmove(text, rs, len);
@@ -1882,7 +1882,7 @@
        if (!port_good_dg(sa))
                return;
 
-       if ((len = endring - rs) >= LINESIZ)
+       if ((len = (size_t)(endring - rs)) >= LINESIZ)
                memmove(text, rs, LINESIZ);
        else {
                memmove(text, rs, len);
@@ -1958,7 +1958,7 @@
        clk = time((time_t *) 0);
 
        len = snprintf(buffer, sizeof buffer, "%.24s\r\n", ctime(&clk));
-       (void) write(s, buffer, len);
+       (void) write(s, buffer, (size_t)len);
 }
 
 /* ARGSUSED */
@@ -1982,7 +1982,7 @@
        if (!port_good_dg(sa))
                return;
        len = snprintf(buffer, sizeof buffer, "%.24s\r\n", ctime(&clk));
-       (void) sendto(s, buffer, len, 0, sa, size);
+       (void) sendto(s, buffer, (size_t)len, 0, sa, size);
 }
 
 #ifdef DEBUG_ENABLE
@@ -2052,7 +2052,7 @@
        ssize_t n;
 
        do {
-               n = read(fd, buf, len-count);
+               n = read(fd, buf, (size_t)(len - count));
                if (n == 0)
                        return (count);
                if (n < 0)
@@ -2240,7 +2240,7 @@
 }
 
 static void
-config_root()
+config_root(void)
 {
        struct servtab *sep;
        /* Uncheck services */
@@ -2438,7 +2438,8 @@
 }
 
 void
-parse_socktype(char* arg, struct servtab* sep) {
+parse_socktype(char* arg, struct servtab* sep)
+{
        /* stream socket may have an accept filter, only check first chars */
        if (strncmp(arg, "stream", sizeof("stream") - 1) == 0)
                sep->se_socktype = SOCK_STREAM;
@@ -2455,7 +2456,8 @@
 }
 
 static struct servtab
-init_servtab() {
+init_servtab(void)
+{
        /* This does not set every field to default. See enter() as well */
        return (struct servtab) {
                /*
@@ -2643,14 +2645,14 @@
 static char *
 gen_file_pattern(const char *cur_config, const char *pattern)
 {
-       if(pattern[0] == '/') {
+       if (pattern[0] == '/') {
                /* Absolute paths don't need any normalization */
                return newstr(pattern);
        }
 
        /* pattern is relative */
        /* Find the end of the file's directory */
-       int i, last = 0;
+       size_t i, last = 0;
        for (i = 0; cur_config[i] != '\0'; i++) {
                if (cur_config[i] == '/') {
                        last = i;
@@ -2822,7 +2824,7 @@
                        .msg_namelen = sizeof(struct sockaddr_storage),
                        /* scatter/gather and control info is null */
                };
-               int count;
+               ssize_t count;
 
                /* Peek so service can still get the packet */
                count = recvmsg(ctrl, &header, MSG_PEEK);
@@ -2879,7 +2881,7 @@
        struct msghdr header = {
                /* All fields null, just consume one message */
        };
-       int count;
+       ssize_t count;
 
        count = recvmsg(ctrl, &header, 0);
        if (count == -1) {
@@ -2893,7 +2895,7 @@
 }
 
 static time_t
-rl_time()
+rl_time(void)
 {
        struct timespec time;
        if(clock_gettime(CLOCK_MONOTONIC, &time) == -1) {
diff -r 4cfe0e1922a0 -r 2b46618b2d98 usr.sbin/inetd/parse_v2.c
--- a/usr.sbin/inetd/parse_v2.c Mon Aug 30 18:03:52 2021 +0000
+++ b/usr.sbin/inetd/parse_v2.c Mon Aug 30 18:21:11 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse_v2.c,v 1.3 2021/08/30 17:32:23 rillig Exp $      */
+/*     $NetBSD: parse_v2.c,v 1.4 2021/08/30 18:21:11 rillig Exp $      */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: parse_v2.c,v 1.3 2021/08/30 17:32:23 rillig Exp $");
+__RCSID("$NetBSD: parse_v2.c,v 1.4 2021/08/30 18:21:11 rillig Exp $");
 
 #include <ctype.h>
 #include <errno.h>
@@ -95,7 +95,7 @@
 static bool infer_protocol_ip_version(struct servtab *);
 static bool    setup_internal(struct servtab *);
 static void    try_infer_socktype(struct servtab *);
-int hex_to_bits(char);
+static int hex_to_bits(char);
 #ifdef IPSEC
 static void    setup_ipsec(struct servtab *);
 #endif
@@ -337,7 +337,7 @@
 {
        char *cp = *cpp;
 
-       int line_start = line_number;
+       size_t line_start = line_number;
 
        for (;;) {
                while (isblank((unsigned char)*cp))
@@ -348,7 +348,7 @@
 
                        /* Should never expect EOF when skipping whitespace */
                        if (cp == NULL) {
-                               ERR("Early end of file after line %d",
+                               ERR("Early end of file after line %zu",
                                    line_start);
                                return false;
                        }
@@ -405,16 +405,14 @@
                        cp++;
                        switch (*cp) {
                        case 'x': {
-                               int temp, bits;
-                               if (((bits = hex_to_bits(*(cp + 1))) == -1)
-                               || ((temp = hex_to_bits(*(cp + 2))) == -1)) {
+                               int hi, lo;
+                               if ((hi = hex_to_bits(cp[1])) == -1
+                               || (lo = hex_to_bits(cp[2])) == -1) {
                                        ERR("Invalid hexcode sequence '%.4s'",
                                            start);
                                        return false;
                                }
-                               bits <<= 4;
-                               bits |= temp;
-                               *start = bits;
+                               *start = (char)((hi << 4) | lo);
                                strmove(cp, 3);
                                continue;
                        }
@@ -459,7 +457,7 @@
        return true;
 }
 
-int
+static int
 hex_to_bits(char in)
 {
        switch(in) {
@@ -511,7 +509,7 @@
         * Found the start of a potential value. Advance one character
         * past the end of the value.
         */
-       char * start = cp;
+       char *start = cp;
        while (!isblank((unsigned char)*cp) && *cp != '#' &&
            *cp != ',' && *cp != ';' && *cp != '\0' ) {
                if (*cp == '"' || *cp == '\'') {



Home | Main Index | Thread Index | Old Index