Module Name:    src
Committed By:   rillig
Date:           Sun Jan 10 23:59:53 UTC 2021

Modified Files:
        src/usr.bin/make: job.c main.c str.c targ.c var.c
        src/usr.bin/make/filemon: filemon_ktrace.c

Log Message:
make(1): make a few more bool expressions more precise

The previous version of lint(1) from a few hours ago didn't catch all
occurrences.  And even the current one doesn't catch everything.
Function arguments and return types still need some work.  The "return
quietly" from shouldDieQuietly still implicitly converts from int to
_Bool.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.396 -r1.397 src/usr.bin/make/job.c
cvs rdiff -u -r1.511 -r1.512 src/usr.bin/make/main.c
cvs rdiff -u -r1.77 -r1.78 src/usr.bin/make/str.c
cvs rdiff -u -r1.159 -r1.160 src/usr.bin/make/targ.c
cvs rdiff -u -r1.780 -r1.781 src/usr.bin/make/var.c
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/make/filemon/filemon_ktrace.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.396 src/usr.bin/make/job.c:1.397
--- src/usr.bin/make/job.c:1.396	Sun Jan 10 21:20:46 2021
+++ src/usr.bin/make/job.c	Sun Jan 10 23:59:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.396 2021/01/10 21:20:46 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.397 2021/01/10 23:59:53 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.396 2021/01/10 21:20:46 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.397 2021/01/10 23:59:53 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -1539,7 +1539,7 @@ JobMakeArgv(Job *job, char **argv)
 		    (!job->echo ? "" :
 			(shell->echoFlag != NULL ? shell->echoFlag : "")));
 
-		if (args[1]) {
+		if (args[1] != '\0') {
 			argv[argc] = args;
 			argc++;
 		}
@@ -2286,7 +2286,7 @@ Job_Init(void)
 static void
 DelSig(int sig)
 {
-	if (sigismember(&caught_signals, sig))
+	if (sigismember(&caught_signals, sig) != 0)
 		(void)bmake_signal(sig, SIG_DFL);
 }
 
@@ -2557,7 +2557,7 @@ JobInterrupt(Boolean runINTERRUPT, int s
 		gn = job->node;
 
 		JobDeleteTarget(gn);
-		if (job->pid) {
+		if (job->pid != 0) {
 			DEBUG2(JOB,
 			    "JobInterrupt passing signal %d to child %d.\n",
 			    signo, job->pid);
@@ -2728,7 +2728,7 @@ clearfd(Job *job)
 		 * pollfd number should be even.
 		 */
 		assert(nfds_per_job() == 2);
-		if (i % 2)
+		if (i % 2 != 0)
 			Punt("odd-numbered fd with meta");
 		nJobs--;
 	}

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.511 src/usr.bin/make/main.c:1.512
--- src/usr.bin/make/main.c:1.511	Sun Jan 10 21:20:46 2021
+++ src/usr.bin/make/main.c	Sun Jan 10 23:59:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.511 2021/01/10 21:20:46 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.512 2021/01/10 23:59:53 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -110,7 +110,7 @@
 #include "trace.h"
 
 /*	"@(#)main.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: main.c,v 1.511 2021/01/10 21:20:46 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.512 2021/01/10 23:59:53 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	    "The Regents of the University of California.  "
@@ -159,7 +159,7 @@ explode(const char *flags)
 	if (flags == NULL)
 		return NULL;
 
-	for (f = flags; *f; f++)
+	for (f = flags; *f != '\0'; f++)
 		if (!ch_isalpha(*f))
 			break;
 
@@ -243,7 +243,7 @@ parse_debug_options(const char *argvalue
 	const char *modules;
 	DebugFlags debug = opts.debug;
 
-	for (modules = argvalue; *modules; ++modules) {
+	for (modules = argvalue; *modules != '\0'; ++modules) {
 		switch (*modules) {
 		case '0':	/* undocumented, only intended for tests */
 			debug = DEBUG_NONE;
@@ -790,7 +790,7 @@ str2Lst_Append(StringList *lp, char *str
 
 	const char *sep = " \t";
 
-	for (n = 0, cp = strtok(str, sep); cp; cp = strtok(NULL, sep)) {
+	for (n = 0, cp = strtok(str, sep); cp != NULL; cp = strtok(NULL, sep)) {
 		Lst_Append(lp, cp);
 		n++;
 	}
@@ -2093,7 +2093,7 @@ shouldDieQuietly(GNode *gn, int bf)
 		else if (bf >= 0)
 			quietly = bf;
 		else
-			quietly = gn != NULL && (gn->type & OP_MAKE);
+			quietly = (gn != NULL && (gn->type & OP_MAKE)) ? 1 : 0;
 	}
 	return quietly;
 }

Index: src/usr.bin/make/str.c
diff -u src/usr.bin/make/str.c:1.77 src/usr.bin/make/str.c:1.78
--- src/usr.bin/make/str.c:1.77	Sun Jan 10 21:20:46 2021
+++ src/usr.bin/make/str.c	Sun Jan 10 23:59:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: str.c,v 1.77 2021/01/10 21:20:46 rillig Exp $	*/
+/*	$NetBSD: str.c,v 1.78 2021/01/10 23:59:53 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -71,7 +71,7 @@
 #include "make.h"
 
 /*	"@(#)str.c	5.8 (Berkeley) 6/1/90"	*/
-MAKE_RCSID("$NetBSD: str.c,v 1.77 2021/01/10 21:20:46 rillig Exp $");
+MAKE_RCSID("$NetBSD: str.c,v 1.78 2021/01/10 23:59:53 rillig Exp $");
 
 /* Return the concatenation of s1 and s2, freshly allocated. */
 char *
@@ -161,7 +161,7 @@ Str_Words(const char *str, Boolean expan
 		switch (ch) {
 		case '"':
 		case '\'':
-			if (inquote) {
+			if (inquote != '\0') {
 				if (inquote == ch)
 					inquote = '\0';
 				else
@@ -189,7 +189,7 @@ Str_Words(const char *str, Boolean expan
 		case ' ':
 		case '\t':
 		case '\n':
-			if (inquote)
+			if (inquote != '\0')
 				break;
 			if (word_start == NULL)
 				continue;

Index: src/usr.bin/make/targ.c
diff -u src/usr.bin/make/targ.c:1.159 src/usr.bin/make/targ.c:1.160
--- src/usr.bin/make/targ.c:1.159	Fri Dec 18 15:47:34 2020
+++ src/usr.bin/make/targ.c	Sun Jan 10 23:59:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: targ.c,v 1.159 2020/12/18 15:47:34 rillig Exp $	*/
+/*	$NetBSD: targ.c,v 1.160 2021/01/10 23:59:53 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -113,7 +113,7 @@
 #include "dir.h"
 
 /*	"@(#)targ.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: targ.c,v 1.159 2020/12/18 15:47:34 rillig Exp $");
+MAKE_RCSID("$NetBSD: targ.c,v 1.160 2021/01/10 23:59:53 rillig Exp $");
 
 /*
  * All target nodes that appeared on the left-hand side of one of the
@@ -514,7 +514,7 @@ Targ_PrintNode(GNode *gn, int pass)
 		}
 		PrintNodeNamesLine("implicit parents", &gn->implicitParents);
 	} else {
-		if (gn->unmade)
+		if (gn->unmade != 0)
 			debug_printf("# %d unmade children\n", gn->unmade);
 	}
 

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.780 src/usr.bin/make/var.c:1.781
--- src/usr.bin/make/var.c:1.780	Sun Jan 10 21:20:47 2021
+++ src/usr.bin/make/var.c	Sun Jan 10 23:59:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.780 2021/01/10 21:20:47 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.781 2021/01/10 23:59:53 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.780 2021/01/10 21:20:47 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.781 2021/01/10 23:59:53 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -1536,7 +1536,7 @@ tryagain:
 		args->matched = TRUE;
 		SepBuf_AddBytes(buf, wp, (size_t)m[0].rm_so);
 
-		for (rp = args->replace; *rp; rp++) {
+		for (rp = args->replace; *rp != '\0'; rp++) {
 			if (*rp == '\\' && (rp[1] == '&' || rp[1] == '\\')) {
 				SepBuf_AddBytes(buf, rp + 1, 1);
 				rp++;
@@ -1840,7 +1840,7 @@ VarHash(const char *str)
 	size_t i;
 
 	size_t len;
-	for (len = len2; len;) {
+	for (len = len2; len != 0;) {
 		uint32_t k = 0;
 		switch (len) {
 		default:

Index: src/usr.bin/make/filemon/filemon_ktrace.c
diff -u src/usr.bin/make/filemon/filemon_ktrace.c:1.11 src/usr.bin/make/filemon/filemon_ktrace.c:1.12
--- src/usr.bin/make/filemon/filemon_ktrace.c:1.11	Sun Jan 10 21:20:47 2021
+++ src/usr.bin/make/filemon/filemon_ktrace.c	Sun Jan 10 23:59:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: filemon_ktrace.c,v 1.11 2021/01/10 21:20:47 rillig Exp $	*/
+/*	$NetBSD: filemon_ktrace.c,v 1.12 2021/01/10 23:59:53 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -519,10 +519,10 @@ top:	/* If the child has exited, nothing
 		return 0;
 
 	/* If we're waiting for input, read some.  */
-	if (F->resid) {
+	if (F->resid > 0) {
 		nread = fread(F->p, 1, F->resid, F->in);
 		if (nread == 0) {
-			if (feof(F->in))
+			if (feof(F->in) != 0)
 				return 0;
 			assert(ferror(F->in) != 0);
 			/*
@@ -539,7 +539,7 @@ top:	/* If the child has exited, nothing
 		assert(nread <= F->resid);
 		F->p += nread;
 		F->resid -= nread;
-		if (F->resid)	/* may be more events */
+		if (F->resid > 0)	/* may be more events */
 			return 1;
 	}
 

Reply via email to