Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make(1): consistently use boolean expressions i...



details:   https://anonhg.NetBSD.org/src/rev/c1228afd18b9
branches:  trunk
changeset: 979793:c1228afd18b9
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 10 21:20:46 2021 +0000

description:
make(1): consistently use boolean expressions in conditions

Most of the make code already followed the style of explicitly writing
(ptr != NULL) instead of the shorter (ptr) in conditions.

The remaining 50 instances have been found by an experimental,
unpublished check in lint(1) that treats bool expressions as
incompatible to any other scalar type, just as in Java, C#, Pascal and
several other languages.

The only unsafe operation on Boolean that is left over is (flags &
FLAG), for an enum implementing a bit set.  If Boolean is an ordinary
integer type (the default), some high bits may get lost.  But if Boolean
is the same as _Bool (by compiling with -DUSE_C99_BOOLEAN), C99 6.3.1.2
defines that a conversion from any scalar to the type _Bool acts as a
comparison to 0, which cannot lose any bits.

diffstat:

 usr.bin/make/compat.c                 |  10 +++++-----
 usr.bin/make/cond.c                   |   6 +++---
 usr.bin/make/dir.c                    |  18 ++++++++++--------
 usr.bin/make/filemon/filemon_ktrace.c |   8 ++++----
 usr.bin/make/for.c                    |   6 +++---
 usr.bin/make/job.c                    |  26 +++++++++++++-------------
 usr.bin/make/main.c                   |   6 +++---
 usr.bin/make/make.c                   |   6 +++---
 usr.bin/make/make.h                   |   4 ++--
 usr.bin/make/meta.c                   |  29 +++++++++++++++--------------
 usr.bin/make/metachar.h               |   4 ++--
 usr.bin/make/parse.c                  |   8 ++++----
 usr.bin/make/str.c                    |   6 +++---
 usr.bin/make/suff.c                   |   6 +++---
 usr.bin/make/var.c                    |   8 ++++----
 15 files changed, 77 insertions(+), 74 deletions(-)

diffs (truncated from 662 to 300 lines):

diff -r 678e2625fc83 -r c1228afd18b9 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Sun Jan 10 20:46:14 2021 +0000
+++ b/usr.bin/make/compat.c     Sun Jan 10 21:20:46 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat.c,v 1.218 2020/12/30 10:03:16 rillig Exp $      */
+/*     $NetBSD: compat.c,v 1.219 2021/01/10 21:20:46 rillig Exp $      */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -96,7 +96,7 @@
 #include "pathnames.h"
 
 /*     "@(#)compat.c   8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: compat.c,v 1.218 2020/12/30 10:03:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.219 2021/01/10 21:20:46 rillig Exp $");
 
 static GNode *curTarg = NULL;
 static pid_t compatChild;
@@ -281,7 +281,7 @@
                        errCheck = FALSE;
                else if (*cmd == '+') {
                        doIt = TRUE;
-                       if (!shellName) /* we came here from jobs */
+                       if (shellName == NULL)  /* we came here from jobs */
                                Shell_Init();
                } else
                        break;
@@ -326,7 +326,7 @@
                /* The following work for any of the builtin shell specs. */
                int shargc = 0;
                shargv[shargc++] = shellPath;
-               if (errCheck && shellErrFlag)
+               if (errCheck && shellErrFlag != NULL)
                        shargv[shargc++] = shellErrFlag;
                shargv[shargc++] = DEBUG(SHELL) ? "-xc" : "-c";
                shargv[shargc++] = cmd;
@@ -707,7 +707,7 @@
 {
        GNode *errorNode = NULL;
 
-       if (!shellName)
+       if (shellName == NULL)
                Shell_Init();
 
        InitSignals();
diff -r 678e2625fc83 -r c1228afd18b9 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Sun Jan 10 20:46:14 2021 +0000
+++ b/usr.bin/make/cond.c       Sun Jan 10 21:20:46 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.234 2021/01/09 16:06:09 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.235 2021/01/10 21:20:46 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
 #include "dir.h"
 
 /*     "@(#)cond.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: cond.c,v 1.234 2021/01/09 16:06:09 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.235 2021/01/10 21:20:46 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -171,7 +171,7 @@
  */
 static Boolean lhsStrict;
 
-static int
+static Boolean
 is_token(const char *str, const char *tok, size_t len)
 {
        return strncmp(str, tok, len) == 0 && !ch_isalpha(str[len]);
diff -r 678e2625fc83 -r c1228afd18b9 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Sun Jan 10 20:46:14 2021 +0000
+++ b/usr.bin/make/dir.c        Sun Jan 10 21:20:46 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.254 2020/12/30 10:03:16 rillig Exp $ */
+/*     $NetBSD: dir.c,v 1.255 2021/01/10 21:20:46 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -137,7 +137,7 @@
 #include "job.h"
 
 /*     "@(#)dir.c      8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: dir.c,v 1.254 2020/12/30 10:03:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.255 2021/01/10 21:20:46 rillig Exp $");
 
 /*
  * A search path is a list of CachedDir structures. A CachedDir has in it the
@@ -1168,7 +1168,8 @@
                                if ((file = DirLookupSubdir(dot, name)) != NULL)
                                        return file;
                        }
-                       if (cur && (file = DirLookupSubdir(cur, name)) != NULL)
+                       if (cur != NULL &&
+                           (file = DirLookupSubdir(cur, name)) != NULL)
                                return file;
                }
 
@@ -1186,12 +1187,13 @@
                }
 
                if (seenDotLast) {
-                       if (dot && !checkedDot) {
+                       if (dot != NULL && !checkedDot) {
                                checkedDot = TRUE;
                                if ((file = DirLookupSubdir(dot, name)) != NULL)
                                        return file;
                        }
-                       if (cur && (file = DirLookupSubdir(cur, name)) != NULL)
+                       if (cur != NULL &&
+                           (file = DirLookupSubdir(cur, name)) != NULL)
                                return file;
                }
 
@@ -1219,7 +1221,7 @@
                 */
                DEBUG0(DIR, "   Trying exact path matches...\n");
 
-               if (!seenDotLast && cur &&
+               if (!seenDotLast && cur != NULL &&
                    ((file = DirLookupAbs(cur, name, base)) != NULL)) {
                        if (file[0] == '\0') {
                                free(file);
@@ -1241,7 +1243,7 @@
                        }
                }
 
-               if (seenDotLast && cur &&
+               if (seenDotLast && cur != NULL &&
                    ((file = DirLookupAbs(cur, name, base)) != NULL)) {
                        if (file[0] == '\0') {
                                free(file);
@@ -1418,7 +1420,7 @@
                        fullName = ResolveMovedDepends(gn);
 
                DEBUG2(DIR, "Found '%s' as '%s'\n",
-                          gn->name, fullName ? fullName : "(not found)");
+                   gn->name, fullName != NULL ? fullName : "(not found)");
        }
 
        if (fullName == NULL)
diff -r 678e2625fc83 -r c1228afd18b9 usr.bin/make/filemon/filemon_ktrace.c
--- a/usr.bin/make/filemon/filemon_ktrace.c     Sun Jan 10 20:46:14 2021 +0000
+++ b/usr.bin/make/filemon/filemon_ktrace.c     Sun Jan 10 21:20:46 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: filemon_ktrace.c,v 1.10 2021/01/09 16:06:09 rillig Exp $       */
+/*     $NetBSD: filemon_ktrace.c,v 1.11 2021/01/10 21:20:47 rillig Exp $       */
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -524,7 +524,7 @@
                if (nread == 0) {
                        if (feof(F->in))
                                return 0;
-                       assert(ferror(F->in));
+                       assert(ferror(F->in) != 0);
                        /*
                         * If interrupted or would block, there may be
                         * more events.  Otherwise fail.
@@ -619,7 +619,7 @@
         * Ignore it if it failed or yielded EJUSTRETURN (-2), or if
         * we're not producing output.
         */
-       if (ret->ktr_error && ret->ktr_error != -2)
+       if (ret->ktr_error != 0 && ret->ktr_error != -2)
                return;
        if (F->out == NULL)
                return;
@@ -645,7 +645,7 @@
         * Ignore it if it failed or yielded EJUSTRETURN (-2), or if
         * we're not producing output.
         */
-       if (ret->ktr_error && ret->ktr_error != -2)
+       if (ret->ktr_error != 0 && ret->ktr_error != -2)
                return;
        if (F->out == NULL)
                return;
diff -r 678e2625fc83 -r c1228afd18b9 usr.bin/make/for.c
--- a/usr.bin/make/for.c        Sun Jan 10 20:46:14 2021 +0000
+++ b/usr.bin/make/for.c        Sun Jan 10 21:20:46 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: for.c,v 1.133 2021/01/09 16:06:09 rillig Exp $ */
+/*     $NetBSD: for.c,v 1.134 2021/01/10 21:20:46 rillig Exp $ */
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -58,7 +58,7 @@
 #include "make.h"
 
 /*     "@(#)for.c      8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: for.c,v 1.133 2021/01/09 16:06:09 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.134 2021/01/10 21:20:46 rillig Exp $");
 
 static int forLevel = 0;       /* Nesting level */
 
@@ -222,7 +222,7 @@
                size_t nitems, nvars;
 
                if ((nitems = f->items.len) > 0 &&
-                   nitems % (nvars = f->vars.len)) {
+                   nitems % (nvars = f->vars.len) != 0) {
                        Parse_Error(PARSE_FATAL,
                            "Wrong number of words (%u) in .for "
                            "substitution list with %u variables",
diff -r 678e2625fc83 -r c1228afd18b9 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Sun Jan 10 20:46:14 2021 +0000
+++ b/usr.bin/make/job.c        Sun Jan 10 21:20:46 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.395 2021/01/09 16:06:09 rillig Exp $ */
+/*     $NetBSD: job.c,v 1.396 2021/01/10 21:20:46 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -143,7 +143,7 @@
 #include "trace.h"
 
 /*     "@(#)job.c      8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.395 2021/01/09 16:06:09 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.396 2021/01/10 21:20:46 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -425,7 +425,7 @@
 static nfds_t nJobs = 0;
 static void watchfd(Job *);
 static void clearfd(Job *);
-static int readyfd(Job *);
+static Boolean readyfd(Job *);
 
 static char *targPrefix = NULL; /* To identify a job change in the output. */
 static Job tokenWaitJob;       /* token wait pseudo-job */
@@ -441,7 +441,7 @@
 static sigset_t caught_signals;        /* Set of signals we handle */
 
 static void JobDoOutput(Job *, Boolean);
-static void JobInterrupt(int, int) MAKE_ATTR_DEAD;
+static void JobInterrupt(Boolean, int) MAKE_ATTR_DEAD;
 static void JobRestartJobs(void);
 static void JobSigReset(void);
 
@@ -952,7 +952,7 @@
                 * set up commands to run through it.
                 */
 
-               if (!shell->hasErrCtl && shell->runChkTmpl &&
+               if (!shell->hasErrCtl && shell->runChkTmpl != NULL &&
                    shell->runChkTmpl[0] != '\0') {
                        if (job->echo && cmdFlags.echo) {
                                ShellWriter_EchoOff(wr);
@@ -1544,11 +1544,11 @@
                        argc++;
                }
        } else {
-               if (!job->ignerr && shell->errFlag) {
+               if (!job->ignerr && shell->errFlag != NULL) {
                        argv[argc] = UNCONST(shell->errFlag);
                        argc++;
                }
-               if (job->echo && shell->echoFlag) {
+               if (job->echo && shell->echoFlag != NULL) {
                        argv[argc] = UNCONST(shell->echoFlag);
                        argc++;
                }
@@ -2090,7 +2090,7 @@
                return;
 
        for (i = npseudojobs * nfds_per_job(); i < nJobs; i++) {
-               if (!fds[i].revents)
+               if (fds[i].revents == 0)
                        continue;
                job = allJobs[i];
                if (job->status == JOB_ST_RUNNING)
@@ -2150,7 +2150,7 @@
        if (shell->echoFlag == NULL)
                shell->echoFlag = "";
        if (shell->hasErrCtl && shell->errFlag[0] != '\0') {
-               if (shellErrFlag &&
+               if (shellErrFlag != NULL &&
                    strcmp(shell->errFlag, &shellErrFlag[1]) != 0) {
                        free(shellErrFlag);
                        shellErrFlag = NULL;
@@ -2509,7 +2509,7 @@
                Shell_Init();
        }
 
-       if (shell->echoOn && shell->echoOff)
+       if (shell->echoOn != NULL && shell->echoOff != NULL)
                shell->hasEchoCtl = TRUE;
 
        if (!shell->hasErrCtl) {
@@ -2539,7 +2539,7 @@
  *     signo           signal received
  */
 static void
-JobInterrupt(int runINTERRUPT, int signo)
+JobInterrupt(Boolean runINTERRUPT, int signo)
 {
        Job *job;               /* job descriptor in that element */



Home | Main Index | Thread Index | Old Index