Module Name:    src
Committed By:   rillig
Date:           Sat Aug 29 13:16:55 UTC 2020

Modified Files:
        src/usr.bin/make: main.c make.c meta.c suff.c var.c

Log Message:
make(1): trust that Var_Subst never returns NULL

It really never does, and it doesn't even report errors.  It just
returns the content of the buffer, up to the first parse error.


To generate a diff of this commit:
cvs rdiff -u -r1.328 -r1.329 src/usr.bin/make/main.c
cvs rdiff -u -r1.129 -r1.130 src/usr.bin/make/make.c
cvs rdiff -u -r1.110 -r1.111 src/usr.bin/make/meta.c
cvs rdiff -u -r1.134 -r1.135 src/usr.bin/make/suff.c
cvs rdiff -u -r1.476 -r1.477 src/usr.bin/make/var.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/main.c
diff -u src/usr.bin/make/main.c:1.328 src/usr.bin/make/main.c:1.329
--- src/usr.bin/make/main.c:1.328	Sat Aug 29 13:04:30 2020
+++ src/usr.bin/make/main.c	Sat Aug 29 13:16:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.328 2020/08/29 13:04:30 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.329 2020/08/29 13:16:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.328 2020/08/29 13:04:30 rillig Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.329 2020/08/29 13:16:54 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19
 #if 0
 static char sccsid[] = "@(#)main.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.328 2020/08/29 13:04:30 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.329 2020/08/29 13:16:54 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1349,13 +1349,11 @@ main(int argc, char **argv)
 			Fatal("%s: cannot open %s.", progname,
 			    (char *)Lst_Datum(ln));
 	} else {
-	    p1 = Var_Subst("${" MAKEFILE_PREFERENCE "}",
-		VAR_CMD, VARE_WANTRES);
-	    if (p1) {
+		p1 = Var_Subst("${" MAKEFILE_PREFERENCE "}",
+			       VAR_CMD, VARE_WANTRES);
 		(void)str2Lst_Append(makefiles, p1, NULL);
 		(void)Lst_Find(makefiles, ReadMakefileSucceeded, NULL);
 		free(p1);
-	    }
 	}
 
 	/* In particular suppress .depend for '-r -V .OBJDIR -f /dev/null' */
@@ -2044,11 +2042,8 @@ PrintOnError(GNode *gn, const char *s)
     }
     expr = "${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'\n@}";
     cp = Var_Subst(expr, VAR_GLOBAL, VARE_WANTRES);
-    if (cp) {
-	if (*cp)
-	    printf("%s", cp);
-	free(cp);
-    }
+    printf("%s", cp);
+    free(cp);
     fflush(stdout);
 
     /*

Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.129 src/usr.bin/make/make.c:1.130
--- src/usr.bin/make/make.c:1.129	Fri Aug 28 04:48:57 2020
+++ src/usr.bin/make/make.c	Sat Aug 29 13:16:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.c,v 1.129 2020/08/28 04:48:57 rillig Exp $	*/
+/*	$NetBSD: make.c,v 1.130 2020/08/29 13:16:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.129 2020/08/28 04:48:57 rillig Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.130 2020/08/29 13:16:54 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)make.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: make.c,v 1.129 2020/08/28 04:48:57 rillig Exp $");
+__RCSID("$NetBSD: make.c,v 1.130 2020/08/29 13:16:54 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -500,7 +500,7 @@ Make_HandleUse(GNode *cgn, GNode *pgn)
 	    free(gn->name);
 	}
 	gn->name = Var_Subst(gn->uname, pgn, VARE_WANTRES);
-	if (gn->name && gn->uname && strcmp(gn->name, gn->uname) != 0) {
+	if (gn->uname && strcmp(gn->name, gn->uname) != 0) {
 	    /* See if we have a target for this node. */
 	    GNode *tgn = Targ_FindNode(gn->name, TARG_NOCREATE);
 	    if (tgn != NULL)

Index: src/usr.bin/make/meta.c
diff -u src/usr.bin/make/meta.c:1.110 src/usr.bin/make/meta.c:1.111
--- src/usr.bin/make/meta.c:1.110	Sat Aug 29 10:41:12 2020
+++ src/usr.bin/make/meta.c	Sat Aug 29 13:16:54 2020
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.c,v 1.110 2020/08/29 10:41:12 rillig Exp $ */
+/*      $NetBSD: meta.c,v 1.111 2020/08/29 13:16:54 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -368,13 +368,13 @@ printCMD(void *cmdp, void *mfpp)
 {
     meta_file_t *mfp = mfpp;
     char *cmd = cmdp;
-    char *cp = NULL;
+    char *cmd_freeIt = NULL;
 
     if (strchr(cmd, '$')) {
-	cmd = cp = Var_Subst(cmd, mfp->gn, VARE_WANTRES);
+	cmd = cmd_freeIt = Var_Subst(cmd, mfp->gn, VARE_WANTRES);
     }
     fprintf(mfp->fp, "CMD %s\n", cmd);
-    free(cp);
+    free(cmd_freeIt);
     return 0;
 }
 
@@ -628,9 +628,7 @@ meta_mode_init(const char *make_mode)
     metaBailiwick = Lst_Init();
     metaBailiwickStr = Var_Subst("${.MAKE.META.BAILIWICK:O:u:tA}",
 	VAR_GLOBAL, VARE_WANTRES);
-    if (metaBailiwickStr) {
-	str2Lst_Append(metaBailiwick, metaBailiwickStr, NULL);
-    }
+    str2Lst_Append(metaBailiwick, metaBailiwickStr, NULL);
     /*
      * We ignore any paths that start with ${.MAKE.META.IGNORE_PATHS}
      */
@@ -639,9 +637,7 @@ meta_mode_init(const char *make_mode)
 	       "/dev /etc /proc /tmp /var/run /var/tmp ${TMPDIR}", VAR_GLOBAL);
     metaIgnorePathsStr = Var_Subst("${" MAKE_META_IGNORE_PATHS ":O:u:tA}",
 				   VAR_GLOBAL, VARE_WANTRES);
-    if (metaIgnorePathsStr) {
-	str2Lst_Append(metaIgnorePaths, metaIgnorePathsStr, NULL);
-    }
+    str2Lst_Append(metaIgnorePaths, metaIgnorePathsStr, NULL);
 
     /*
      * We ignore any paths that match ${.MAKE.META.IGNORE_PATTERNS}

Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.134 src/usr.bin/make/suff.c:1.135
--- src/usr.bin/make/suff.c:1.134	Sat Aug 29 12:01:46 2020
+++ src/usr.bin/make/suff.c	Sat Aug 29 13:16:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.134 2020/08/29 12:01:46 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.135 2020/08/29 13:16:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.134 2020/08/29 12:01:46 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.135 2020/08/29 13:16:54 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)suff.c	8.4 (Berkeley) 3/21/94";
 #else
-__RCSID("$NetBSD: suff.c,v 1.134 2020/08/29 12:01:46 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.135 2020/08/29 13:16:54 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1281,7 +1281,7 @@ SuffExpandChildren(LstNode cln, GNode *p
     }
     cp = Var_Subst(cgn->name, pgn, VARE_UNDEFERR|VARE_WANTRES);
 
-    if (cp != NULL) {
+    {
 	Lst	    members = Lst_Init();
 
 	if (cgn->type & OP_ARCHV) {
@@ -1384,6 +1384,7 @@ SuffExpandChildren(LstNode cln, GNode *p
 	 */
 	free(cp);
     }
+
     if (DEBUG(SUFF)) {
 	fprintf(debug_file, "\n");
     }

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.476 src/usr.bin/make/var.c:1.477
--- src/usr.bin/make/var.c:1.476	Sat Aug 29 12:48:17 2020
+++ src/usr.bin/make/var.c	Sat Aug 29 13:16:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.476 2020/08/29 12:48:17 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.477 2020/08/29 13:16:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.476 2020/08/29 12:48:17 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.477 2020/08/29 13:16:54 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.476 2020/08/29 12:48:17 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.477 2020/08/29 13:16:54 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -721,7 +721,7 @@ Var_UnExport(const char *str)
 					       VAR_GLOBAL, VARE_WANTRES);
     }
 
-    if (TRUE) {
+    {
 	Var *v;
 	char **av;
 	char *as;
@@ -1464,14 +1464,12 @@ ModifyWord_Loop(const char *word, SepBuf
 
     VAR_DEBUG("ModifyWord_Loop: in \"%s\", replace \"%s\" with \"%s\" "
 	      "to \"%s\"\n",
-	      word, args->tvar, args->str, s ? s : "(null)");
+	      word, args->tvar, args->str, s);
 
-    if (s != NULL && s[0] != '\0') {
-	if (s[0] == '\n' || (buf->buf.count > 0 &&
-			     buf->buf.buffer[buf->buf.count - 1] == '\n'))
-	    buf->needSep = FALSE;
-	SepBuf_AddStr(buf, s);
-    }
+    if (s[0] == '\n' || (buf->buf.count > 0 &&
+			 buf->buf.buffer[buf->buf.count - 1] == '\n'))
+	buf->needSep = FALSE;
+    SepBuf_AddStr(buf, s);
     free(s);
 }
 
@@ -3615,7 +3613,6 @@ Var_Parse(const char * const str, GNode 
     if (strchr(nstr, '$') != NULL && (eflags & VARE_WANTRES) != 0) {
 	nstr = Var_Subst(nstr, ctxt, eflags);
 	*freePtr = nstr;
-	assert(nstr != NULL);
     }
 
     v->flags &= ~(unsigned)VAR_IN_USE;

Reply via email to