Module Name:    src
Committed By:   rillig
Date:           Tue Feb 14 21:38:31 UTC 2023

Modified Files:
        src/usr.bin/make: compat.c for.c job.c main.c make.c make.h meta.c
            parse.c suff.c var.c

Log Message:
make: clean up calls to Var_Subst

None of the calls to Var_Subst used the return value, and the return
value was always VPR_OK.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.244 -r1.245 src/usr.bin/make/compat.c
cvs rdiff -u -r1.170 -r1.171 src/usr.bin/make/for.c
cvs rdiff -u -r1.457 -r1.458 src/usr.bin/make/job.c
cvs rdiff -u -r1.589 -r1.590 src/usr.bin/make/main.c
cvs rdiff -u -r1.258 -r1.259 src/usr.bin/make/make.c
cvs rdiff -u -r1.312 -r1.313 src/usr.bin/make/make.h
cvs rdiff -u -r1.201 -r1.202 src/usr.bin/make/meta.c
cvs rdiff -u -r1.693 -r1.694 src/usr.bin/make/parse.c
cvs rdiff -u -r1.367 -r1.368 src/usr.bin/make/suff.c
cvs rdiff -u -r1.1042 -r1.1043 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/compat.c
diff -u src/usr.bin/make/compat.c:1.244 src/usr.bin/make/compat.c:1.245
--- src/usr.bin/make/compat.c:1.244	Tue Jan 17 21:35:19 2023
+++ src/usr.bin/make/compat.c	Tue Feb 14 21:38:31 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.244 2023/01/17 21:35:19 christos Exp $	*/
+/*	$NetBSD: compat.c,v 1.245 2023/02/14 21:38:31 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -91,7 +91,7 @@
 #include "pathnames.h"
 
 /*	"@(#)compat.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: compat.c,v 1.244 2023/01/17 21:35:19 christos Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.245 2023/02/14 21:38:31 rillig Exp $");
 
 static GNode *curTarg = NULL;
 static pid_t compatChild;
@@ -238,7 +238,7 @@ Compat_RunCommand(const char *cmdp, GNod
 	errCheck = !(gn->type & OP_IGNORE);
 	doIt = false;
 
-	(void)Var_Subst(cmd, gn, VARE_WANTRES, &cmdStart);
+	cmdStart = Var_Subst(cmd, gn, VARE_WANTRES);
 	/* TODO: handle errors */
 
 	if (cmdStart[0] == '\0') {

Index: src/usr.bin/make/for.c
diff -u src/usr.bin/make/for.c:1.170 src/usr.bin/make/for.c:1.171
--- src/usr.bin/make/for.c:1.170	Sat Sep  3 00:50:07 2022
+++ src/usr.bin/make/for.c	Tue Feb 14 21:38:31 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.170 2022/09/03 00:50:07 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.171 2023/02/14 21:38:31 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.170 2022/09/03 00:50:07 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.171 2023/02/14 21:38:31 rillig Exp $");
 
 
 typedef struct ForLoop {
@@ -168,7 +168,9 @@ ForLoop_ParseItems(ForLoop *f, const cha
 
 	cpp_skip_whitespace(&p);
 
-	if (Var_Subst(p, SCOPE_GLOBAL, VARE_WANTRES, &items) != VPR_OK) {
+	items = Var_Subst(p, SCOPE_GLOBAL, VARE_WANTRES);
+	if (items == var_Error) {
+		/* TODO: Make this part of the code reachable. */
 		Parse_Error(PARSE_FATAL, "Error in .for loop items");
 		return false;
 	}

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.457 src/usr.bin/make/job.c:1.458
--- src/usr.bin/make/job.c:1.457	Tue Jan 17 21:35:19 2023
+++ src/usr.bin/make/job.c	Tue Feb 14 21:38:31 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.457 2023/01/17 21:35:19 christos Exp $	*/
+/*	$NetBSD: job.c,v 1.458 2023/02/14 21:38:31 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -142,7 +142,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.457 2023/01/17 21:35:19 christos Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.458 2023/02/14 21:38:31 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -911,7 +911,7 @@ JobWriteCommand(Job *job, ShellWriter *w
 
 	run = GNode_ShouldExecute(job->node);
 
-	(void)Var_Subst(ucmd, job->node, VARE_WANTRES, &xcmd);
+	xcmd = Var_Subst(ucmd, job->node, VARE_WANTRES);
 	/* TODO: handle errors */
 	xcmdStart = xcmd;
 
@@ -1040,7 +1040,7 @@ JobSaveCommands(Job *job)
 		 * variables such as .TARGET, .IMPSRC.  It is not intended to
 		 * expand the other variables as well; see deptgt-end.mk.
 		 */
-		(void)Var_Subst(cmd, job->node, VARE_WANTRES, &expanded_cmd);
+		expanded_cmd = Var_Subst(cmd, job->node, VARE_WANTRES);
 		/* TODO: handle errors */
 		Lst_Append(&Targ_GetEndNode()->commands, expanded_cmd);
 	}
@@ -1076,8 +1076,7 @@ DebugFailedJob(const Job *job)
 		debug_printf("\t%s\n", cmd);
 
 		if (strchr(cmd, '$') != NULL) {
-			char *xcmd;
-			(void)Var_Subst(cmd, job->node, VARE_WANTRES, &xcmd);
+			char *xcmd = Var_Subst(cmd, job->node, VARE_WANTRES);
 			debug_printf("\t=> %s\n", xcmd);
 			free(xcmd);
 		}
@@ -2201,8 +2200,8 @@ Job_SetPrefix(void)
 		Global_Set(MAKE_JOB_PREFIX, "---");
 	}
 
-	(void)Var_Subst("${" MAKE_JOB_PREFIX "}",
-	    SCOPE_GLOBAL, VARE_WANTRES, &targPrefix);
+	targPrefix = Var_Subst("${" MAKE_JOB_PREFIX "}",
+	    SCOPE_GLOBAL, VARE_WANTRES);
 	/* TODO: handle errors */
 }
 

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.589 src/usr.bin/make/main.c:1.590
--- src/usr.bin/make/main.c:1.589	Thu Jan 26 20:48:17 2023
+++ src/usr.bin/make/main.c	Tue Feb 14 21:38:31 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.589 2023/01/26 20:48:17 sjg Exp $	*/
+/*	$NetBSD: main.c,v 1.590 2023/02/14 21:38:31 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
 #include "trace.h"
 
 /*	"@(#)main.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: main.c,v 1.589 2023/01/26 20:48:17 sjg Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.590 2023/02/14 21:38:31 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	    "The Regents of the University of California.  "
@@ -788,9 +788,8 @@ siginfo(int signo MAKE_ATTR_UNUSED)
 static void
 MakeMode(void)
 {
-	char *mode;
-
-	(void)Var_Subst("${" MAKE_MODE ":tl}", SCOPE_GLOBAL, VARE_WANTRES, &mode);
+	char *mode = Var_Subst("${" MAKE_MODE ":tl}",
+	    SCOPE_GLOBAL, VARE_WANTRES);
 	/* TODO: handle errors */
 
 	if (mode[0] != '\0') {
@@ -813,16 +812,14 @@ static void
 PrintVar(const char *varname, bool expandVars)
 {
 	if (strchr(varname, '$') != NULL) {
-		char *evalue;
-		(void)Var_Subst(varname, SCOPE_GLOBAL, VARE_WANTRES, &evalue);
+		char *evalue = Var_Subst(varname, SCOPE_GLOBAL, VARE_WANTRES);
 		/* TODO: handle errors */
 		printf("%s\n", evalue);
 		free(evalue);
 
 	} else if (expandVars) {
 		char *expr = str_concat3("${", varname, "}");
-		char *evalue;
-		(void)Var_Subst(expr, SCOPE_GLOBAL, VARE_WANTRES, &evalue);
+		char *evalue = Var_Subst(expr, SCOPE_GLOBAL, VARE_WANTRES);
 		/* TODO: handle errors */
 		free(expr);
 		printf("%s\n", evalue);
@@ -848,7 +845,7 @@ GetBooleanExpr(const char *expr, bool fa
 	char *value;
 	bool res;
 
-	(void)Var_Subst(expr, SCOPE_GLOBAL, VARE_WANTRES, &value);
+	value = Var_Subst(expr, SCOPE_GLOBAL, VARE_WANTRES);
 	/* TODO: handle errors */
 	res = ParseBoolean(value, fallback);
 	free(value);
@@ -1205,7 +1202,7 @@ InitMaxJobs(void)
 	    !Var_Exists(SCOPE_GLOBAL, ".MAKE.JOBS"))
 		return;
 
-	(void)Var_Subst("${.MAKE.JOBS}", SCOPE_GLOBAL, VARE_WANTRES, &value);
+	value = Var_Subst("${.MAKE.JOBS}", SCOPE_GLOBAL, VARE_WANTRES);
 	/* TODO: handle errors */
 	n = (int)strtol(value, NULL, 0);
 	if (n < 1) {
@@ -1240,7 +1237,7 @@ InitVpath(void)
 	if (!Var_Exists(SCOPE_CMDLINE, "VPATH"))
 		return;
 
-	(void)Var_Subst("${VPATH}", SCOPE_CMDLINE, VARE_WANTRES, &vpath);
+	vpath = Var_Subst("${VPATH}", SCOPE_CMDLINE, VARE_WANTRES);
 	/* TODO: handle errors */
 	path = vpath;
 	do {
@@ -1276,10 +1273,8 @@ ReadFirstDefaultMakefile(void)
 {
 	StringList makefiles = LST_INIT;
 	StringListNode *ln;
-	char *prefs;
-
-	(void)Var_Subst("${" MAKE_MAKEFILE_PREFERENCE "}",
-	    SCOPE_CMDLINE, VARE_WANTRES, &prefs);
+	char *prefs = Var_Subst("${" MAKE_MAKEFILE_PREFERENCE "}",
+	    SCOPE_CMDLINE, VARE_WANTRES);
 	/* TODO: handle errors */
 
 	(void)str2Lst_Append(&makefiles, prefs);
@@ -1498,8 +1493,8 @@ main_PrepareMaking(void)
 {
 	/* In particular suppress .depend for '-r -V .OBJDIR -f /dev/null' */
 	if (!opts.noBuiltins || opts.printVars == PVM_NONE) {
-		(void)Var_Subst("${.MAKE.DEPENDFILE}",
-		    SCOPE_CMDLINE, VARE_WANTRES, &makeDependfile);
+		makeDependfile = Var_Subst("${.MAKE.DEPENDFILE}",
+		    SCOPE_CMDLINE, VARE_WANTRES);
 		if (makeDependfile[0] != '\0') {
 			/* TODO: handle errors */
 			doing_depend = true;
@@ -2061,9 +2056,9 @@ PrintOnError(GNode *gn, const char *msg)
 		SetErrorVars(gn);
 
 	{
-		char *errorVarsValues;
-		(void)Var_Subst("${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'\n@}",
-		    SCOPE_GLOBAL, VARE_WANTRES, &errorVarsValues);
+		char *errorVarsValues = Var_Subst(
+		    "${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'\n@}",
+		    SCOPE_GLOBAL, VARE_WANTRES);
 		/* TODO: handle errors */
 		printf("%s", errorVarsValues);
 		free(errorVarsValues);
@@ -2091,9 +2086,9 @@ Main_ExportMAKEFLAGS(bool first)
 		return;
 	once = false;
 
-	(void)Var_Subst(
+	flags = Var_Subst(
 	    "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}",
-	    SCOPE_CMDLINE, VARE_WANTRES, &flags);
+	    SCOPE_CMDLINE, VARE_WANTRES);
 	/* TODO: handle errors */
 	if (flags[0] != '\0') {
 #ifdef POSIX
@@ -2114,8 +2109,8 @@ getTmpdir(void)
 		return tmpdir;
 
 	/* Honor $TMPDIR if it is valid, strip a trailing '/'. */
-	(void)Var_Subst("${TMPDIR:tA:U" _PATH_TMP ":S,/$,,W}/",
-	    SCOPE_GLOBAL, VARE_WANTRES, &tmpdir);
+	tmpdir = Var_Subst("${TMPDIR:tA:U" _PATH_TMP ":S,/$,,W}/",
+	    SCOPE_GLOBAL, VARE_WANTRES);
 	/* TODO: handle errors */
 
 	if (stat(tmpdir, &st) < 0 || !S_ISDIR(st.st_mode)) {

Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.258 src/usr.bin/make/make.c:1.259
--- src/usr.bin/make/make.c:1.258	Mon Dec  5 23:28:08 2022
+++ src/usr.bin/make/make.c	Tue Feb 14 21:38:31 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.c,v 1.258 2022/12/05 23:28:08 rillig Exp $	*/
+/*	$NetBSD: make.c,v 1.259 2023/02/14 21:38:31 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -104,7 +104,7 @@
 #include "job.h"
 
 /*	"@(#)make.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: make.c,v 1.258 2022/12/05 23:28:08 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.259 2023/02/14 21:38:31 rillig Exp $");
 
 /* Sequence # to detect recursion. */
 static unsigned int checked_seqno = 1;
@@ -445,7 +445,7 @@ Make_HandleUse(GNode *cgn, GNode *pgn)
 		} else {
 			free(gn->name);
 		}
-		(void)Var_Subst(gn->uname, pgn, VARE_WANTRES, &gn->name);
+		gn->name = Var_Subst(gn->uname, pgn, VARE_WANTRES);
 		/* TODO: handle errors */
 		if (gn->uname != NULL && strcmp(gn->name, gn->uname) != 0) {
 			/* See if we have a target for this node. */

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.312 src/usr.bin/make/make.h:1.313
--- src/usr.bin/make/make.h:1.312	Tue Feb 14 21:08:00 2023
+++ src/usr.bin/make/make.h	Tue Feb 14 21:38:31 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.312 2023/02/14 21:08:00 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.313 2023/02/14 21:38:31 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -1018,7 +1018,7 @@ bool Var_ExistsExpand(GNode *, const cha
 FStr Var_Value(GNode *, const char *) MAKE_ATTR_USE;
 const char *GNode_ValueDirect(GNode *, const char *) MAKE_ATTR_USE;
 FStr Var_Parse(const char **, GNode *, VarEvalMode);
-VarParseResult Var_Subst(const char *, GNode *, VarEvalMode, char **);
+char *Var_Subst(const char *, GNode *, VarEvalMode);
 void Var_Expand(FStr *, GNode *, VarEvalMode);
 void Var_Stats(void);
 void Var_Dump(GNode *);

Index: src/usr.bin/make/meta.c
diff -u src/usr.bin/make/meta.c:1.201 src/usr.bin/make/meta.c:1.202
--- src/usr.bin/make/meta.c:1.201	Wed Sep 28 16:34:47 2022
+++ src/usr.bin/make/meta.c	Tue Feb 14 21:38:31 2023
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.c,v 1.201 2022/09/28 16:34:47 sjg Exp $ */
+/*      $NetBSD: meta.c,v 1.202 2023/02/14 21:38:31 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -321,7 +321,7 @@ is_submake(const char *cmd, GNode *gn)
 	p_len = strlen(p_make);
     }
     if (strchr(cmd, '$') != NULL) {
-	(void)Var_Subst(cmd, gn, VARE_WANTRES, &mp);
+	mp = Var_Subst(cmd, gn, VARE_WANTRES);
 	/* TODO: handle errors */
 	cmd = mp;
     }
@@ -475,10 +475,8 @@ meta_create(BuildMon *pbm, GNode *gn)
     dname.str = objdir_realpath;
 
     if (metaVerbose) {
-	char *mp;
-
 	/* Describe the target we are building */
-	(void)Var_Subst("${" MAKE_META_PREFIX "}", gn, VARE_WANTRES, &mp);
+	char *mp = Var_Subst("${" MAKE_META_PREFIX "}", gn, VARE_WANTRES);
 	/* TODO: handle errors */
 	if (mp[0] != '\0')
 	    fprintf(stdout, "%s\n", mp);
@@ -614,8 +612,8 @@ meta_mode_init(const char *make_mode)
     /*
      * We consider ourselves master of all within ${.MAKE.META.BAILIWICK}
      */
-    (void)Var_Subst("${.MAKE.META.BAILIWICK:O:u:tA}",
-		    SCOPE_GLOBAL, VARE_WANTRES, &metaBailiwickStr);
+    metaBailiwickStr = Var_Subst("${.MAKE.META.BAILIWICK:O:u:tA}",
+				 SCOPE_GLOBAL, VARE_WANTRES);
     /* TODO: handle errors */
     str2Lst_Append(&metaBailiwick, metaBailiwickStr);
     /*
@@ -623,8 +621,8 @@ meta_mode_init(const char *make_mode)
      */
     Global_Append(MAKE_META_IGNORE_PATHS,
 	       "/dev /etc /proc /tmp /var/run /var/tmp ${TMPDIR}");
-    (void)Var_Subst("${" MAKE_META_IGNORE_PATHS ":O:u:tA}",
-		    SCOPE_GLOBAL, VARE_WANTRES, &metaIgnorePathsStr);
+    metaIgnorePathsStr = Var_Subst("${" MAKE_META_IGNORE_PATHS ":O:u:tA}",
+				   SCOPE_GLOBAL, VARE_WANTRES);
     /* TODO: handle errors */
     str2Lst_Append(&metaIgnorePaths, metaIgnorePathsStr);
 
@@ -794,8 +792,8 @@ meta_job_output(Job *job, char *cp, cons
 	    if (meta_prefix == NULL) {
 		char *cp2;
 
-		(void)Var_Subst("${" MAKE_META_PREFIX "}",
-				SCOPE_GLOBAL, VARE_WANTRES, &meta_prefix);
+		meta_prefix = Var_Subst("${" MAKE_META_PREFIX "}",
+					SCOPE_GLOBAL, VARE_WANTRES);
 		/* TODO: handle errors */
 		if ((cp2 = strchr(meta_prefix, '$')) != NULL)
 		    meta_prefix_len = (size_t)(cp2 - meta_prefix);
@@ -982,7 +980,7 @@ meta_ignore(GNode *gn, const char *p)
 	 */
 	Var_Set(gn, ".p.", p);
 	expr = "${" MAKE_META_IGNORE_PATTERNS ":@m@${.p.:M$m}@}";
-	(void)Var_Subst(expr, gn, VARE_WANTRES, &pm);
+	pm = Var_Subst(expr, gn, VARE_WANTRES);
 	/* TODO: handle errors */
 	if (pm[0] != '\0') {
 #ifdef DEBUG_META_MODE
@@ -1001,7 +999,7 @@ meta_ignore(GNode *gn, const char *p)
 	snprintf(fname, sizeof fname,
 		 "${%s:L:${%s:ts:}}",
 		 p, MAKE_META_IGNORE_FILTER);
-	(void)Var_Subst(fname, gn, VARE_WANTRES, &fm);
+	fm = Var_Subst(fname, gn, VARE_WANTRES);
 	/* TODO: handle errors */
 	if (*fm == '\0') {
 #ifdef DEBUG_META_MODE
@@ -1059,7 +1057,9 @@ static char *
 meta_filter_cmd(GNode *gn, char *s)
 {
     Var_Set(gn, META_CMD_FILTER_VAR, s);
-    Var_Subst("${" META_CMD_FILTER_VAR ":${" MAKE_META_CMP_FILTER ":ts:}}", gn, VARE_WANTRES, &s);
+    s = Var_Subst(
+	"${" META_CMD_FILTER_VAR ":${" MAKE_META_CMP_FILTER ":ts:}}",
+	gn, VARE_WANTRES);
     return s;
 }
 
@@ -1527,7 +1527,7 @@ meta_oodate(GNode *gn, bool oodate)
 			DEBUG2(META, "%s: %u: cannot compare command using .OODATE\n",
 			       fname, lineno);
 		    }
-		    (void)Var_Subst(cmd, gn, VARE_UNDEFERR, &cmd);
+		    cmd = Var_Subst(cmd, gn, VARE_UNDEFERR);
 		    /* TODO: handle errors */
 
 		    if ((cp = strchr(cmd, '\n')) != NULL) {

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.693 src/usr.bin/make/parse.c:1.694
--- src/usr.bin/make/parse.c:1.693	Tue Feb 14 21:08:00 2023
+++ src/usr.bin/make/parse.c	Tue Feb 14 21:38:31 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.693 2023/02/14 21:08:00 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.694 2023/02/14 21:38:31 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -105,7 +105,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.693 2023/02/14 21:08:00 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.694 2023/02/14 21:38:31 rillig Exp $");
 
 /*
  * A file being read.
@@ -578,7 +578,7 @@ HandleMessage(ParseErrorLevel level, con
 		return;
 	}
 
-	(void)Var_Subst(umsg, SCOPE_CMDLINE, VARE_WANTRES, &xmsg);
+	xmsg = Var_Subst(umsg, SCOPE_CMDLINE, VARE_WANTRES);
 	/* TODO: handle errors */
 
 	Parse_Error(level, "%s", xmsg);
@@ -1774,10 +1774,8 @@ VarCheckSyntax(VarAssignOp type, const c
 {
 	if (opts.strict) {
 		if (type != VAR_SUBST && strchr(uvalue, '$') != NULL) {
-			char *expandedValue;
-
-			(void)Var_Subst(uvalue, scope, VARE_PARSE_ONLY,
-			    &expandedValue);
+			char *expandedValue = Var_Subst(uvalue,
+			    scope, VARE_PARSE_ONLY);
 			/* TODO: handle errors */
 			free(expandedValue);
 		}
@@ -1803,7 +1801,7 @@ VarAssign_EvalSubst(GNode *scope, const 
 	if (!Var_ExistsExpand(scope, name))
 		Var_SetExpand(scope, name, "");
 
-	(void)Var_Subst(uvalue, scope, VARE_KEEP_DOLLAR_UNDEF, &evalue);
+	evalue = Var_Subst(uvalue, scope, VARE_KEEP_DOLLAR_UNDEF);
 	/* TODO: handle errors */
 
 	Var_SetExpand(scope, name, evalue);
@@ -2240,7 +2238,7 @@ ParseTraditionalInclude(char *line)
 
 	pp_skip_whitespace(&file);
 
-	(void)Var_Subst(file, SCOPE_CMDLINE, VARE_WANTRES, &all_files);
+	all_files = Var_Subst(file, SCOPE_CMDLINE, VARE_WANTRES);
 	/* TODO: handle errors */
 
 	for (file = all_files; !done; file = cp + 1) {
@@ -2285,7 +2283,7 @@ ParseGmakeExport(char *line)
 	/*
 	 * Expand the value before putting it in the environment.
 	 */
-	(void)Var_Subst(value, SCOPE_CMDLINE, VARE_WANTRES, &value);
+	value = Var_Subst(value, SCOPE_CMDLINE, VARE_WANTRES);
 	/* TODO: handle errors */
 
 	setenv(variable, value, 1);
@@ -2862,7 +2860,7 @@ ParseDependencyLine(char *line)
 	 * Var_Subst.
 	 */
 	emode = opts.strict ? VARE_WANTRES : VARE_UNDEFERR;
-	(void)Var_Subst(line, SCOPE_CMDLINE, emode, &expanded_line);
+	expanded_line = Var_Subst(line, SCOPE_CMDLINE, emode);
 	/* TODO: handle errors */
 
 	/* Need a fresh list for the target nodes */

Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.367 src/usr.bin/make/suff.c:1.368
--- src/usr.bin/make/suff.c:1.367	Tue Feb 14 21:08:00 2023
+++ src/usr.bin/make/suff.c	Tue Feb 14 21:38:31 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: suff.c,v 1.367 2023/02/14 21:08:00 rillig Exp $	*/
+/*	$NetBSD: suff.c,v 1.368 2023/02/14 21:38:31 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -115,7 +115,7 @@
 #include "dir.h"
 
 /*	"@(#)suff.c	8.4 (Berkeley) 3/21/94"	*/
-MAKE_RCSID("$NetBSD: suff.c,v 1.367 2023/02/14 21:08:00 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.368 2023/02/14 21:38:31 rillig Exp $");
 
 typedef List SuffixList;
 typedef ListNode SuffixListNode;
@@ -1383,7 +1383,7 @@ ExpandChildren(GNodeListNode *cln, GNode
 	}
 
 	DEBUG1(SUFF, "Expanding \"%s\"...", cgn->name);
-	(void)Var_Subst(cgn->name, pgn, VARE_UNDEFERR, &cp);
+	cp = Var_Subst(cgn->name, pgn, VARE_UNDEFERR);
 	/* TODO: handle errors */
 
 	{

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.1042 src/usr.bin/make/var.c:1.1043
--- src/usr.bin/make/var.c:1.1042	Tue Feb 14 21:08:00 2023
+++ src/usr.bin/make/var.c	Tue Feb 14 21:38:31 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1042 2023/02/14 21:08:00 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1043 2023/02/14 21:38:31 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1042 2023/02/14 21:08:00 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1043 2023/02/14 21:38:31 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -537,7 +537,6 @@ Var_Delete(GNode *scope, const char *var
 void
 Var_Undef(const char *arg)
 {
-	VarParseResult vpr;
 	char *expanded;
 	Words varnames;
 	size_t i;
@@ -548,8 +547,9 @@ Var_Undef(const char *arg)
 		return;
 	}
 
-	vpr = Var_Subst(arg, SCOPE_GLOBAL, VARE_WANTRES, &expanded);
-	if (vpr != VPR_OK) {
+	expanded = Var_Subst(arg, SCOPE_GLOBAL, VARE_WANTRES);
+	if (expanded == var_Error) {
+		/* TODO: Make this part of the code reachable. */
 		Parse_Error(PARSE_FATAL,
 		    "Error in variable names to be undefined");
 		return;
@@ -619,7 +619,7 @@ ExportVarEnv(Var *v)
 
 	/* XXX: name is injected without escaping it */
 	expr = str_concat3("${", name, "}");
-	(void)Var_Subst(expr, SCOPE_GLOBAL, VARE_WANTRES, &val);
+	val = Var_Subst(expr, SCOPE_GLOBAL, VARE_WANTRES);
 	/* TODO: handle errors */
 	setenv(name, val, 1);
 	free(val);
@@ -719,8 +719,8 @@ Var_ReexportVars(void)
 		return;
 	}
 
-	(void)Var_Subst("${" MAKE_EXPORTED ":O:u}", SCOPE_GLOBAL, VARE_WANTRES,
-	    &xvarnames);
+	xvarnames = Var_Subst("${" MAKE_EXPORTED ":O:u}", SCOPE_GLOBAL,
+	    VARE_WANTRES);
 	/* TODO: handle errors */
 	if (xvarnames[0] != '\0') {
 		Words varnames = Str_Words(xvarnames, false);
@@ -760,9 +760,7 @@ ExportVars(const char *varnames, bool is
 static void
 ExportVarsExpand(const char *uvarnames, bool isExport, VarExportMode mode)
 {
-	char *xvarnames;
-
-	(void)Var_Subst(uvarnames, SCOPE_GLOBAL, VARE_WANTRES, &xvarnames);
+	char *xvarnames = Var_Subst(uvarnames, SCOPE_GLOBAL, VARE_WANTRES);
 	/* TODO: handle errors */
 	ExportVars(xvarnames, isExport, mode);
 	free(xvarnames);
@@ -838,10 +836,9 @@ GetVarnamesToUnexport(bool isEnv, const 
 	}
 
 	if (what != UNEXPORT_NAMED) {
-		char *expanded;
 		/* Using .MAKE.EXPORTED */
-		(void)Var_Subst("${" MAKE_EXPORTED ":O:u}", SCOPE_GLOBAL,
-		    VARE_WANTRES, &expanded);
+		char *expanded = Var_Subst("${" MAKE_EXPORTED ":O:u}",
+		    SCOPE_GLOBAL, VARE_WANTRES);
 		/* TODO: handle errors */
 		varnames = FStr_InitOwn(expanded);
 	}
@@ -872,8 +869,7 @@ UnexportVar(Substring varname, UnexportW
 		/* XXX: v->name is injected without escaping it */
 		char *expr = str_concat3("${" MAKE_EXPORTED ":N",
 		    v->name.str, "}");
-		char *cp;
-		(void)Var_Subst(expr, SCOPE_GLOBAL, VARE_WANTRES, &cp);
+		char *cp = Var_Subst(expr, SCOPE_GLOBAL, VARE_WANTRES);
 		/* TODO: handle errors */
 		Global_Set(MAKE_EXPORTED, cp);
 		free(cp);
@@ -1698,7 +1694,7 @@ ModifyWord_Loop(Substring word, SepBuf *
 	assert(word.end[0] == '\0');	/* assume null-terminated word */
 	Var_SetWithFlags(args->scope, args->var, word.start,
 	    VAR_SET_NO_EXPORT);
-	(void)Var_Subst(args->body, args->scope, args->emode, &s);
+	s = Var_Subst(args->body, args->scope, args->emode);
 	/* TODO: handle errors */
 
 	assert(word.end[0] == '\0');	/* assume null-terminated word */
@@ -2805,7 +2801,7 @@ ParseModifier_Match(const char **pp, con
 		 * XXX: Contrary to ParseModifierPart, a dollar in a ':M' or
 		 * ':N' modifier must be escaped as '$$', not as '\$'.
 		 */
-		(void)Var_Subst(pattern, expr->scope, expr->emode, &pattern);
+		pattern = Var_Subst(pattern, expr->scope, expr->emode);
 		/* TODO: handle errors */
 		free(old_pattern);
 	}
@@ -4572,8 +4568,7 @@ Var_Parse(const char **pp, GNode *scope,
 		if (opts.strict)
 			nested_emode = VarEvalMode_UndefOk(nested_emode);
 		v->inUse = true;
-		(void)Var_Subst(Expr_Str(&expr), scope, nested_emode,
-		    &expanded);
+		expanded = Var_Subst(Expr_Str(&expr), scope, nested_emode);
 		v->inUse = false;
 		/* TODO: handle errors */
 		Expr_SetValueOwn(&expr, expanded);
@@ -4711,8 +4706,8 @@ VarSubstPlain(const char **pp, Buffer *r
  *			variables.  The other scopes are searched as well.
  *	emode		The mode for parsing or evaluating subexpressions.
  */
-VarParseResult
-Var_Subst(const char *str, GNode *scope, VarEvalMode emode, char **out_res)
+char *
+Var_Subst(const char *str, GNode *scope, VarEvalMode emode)
 {
 	const char *p = str;
 	Buffer res;
@@ -4736,8 +4731,7 @@ Var_Subst(const char *str, GNode *scope,
 			VarSubstPlain(&p, &res);
 	}
 
-	*out_res = Buf_DoneDataCompact(&res);
-	return VPR_OK;
+	return Buf_DoneDataCompact(&res);
 }
 
 void
@@ -4747,7 +4741,7 @@ Var_Expand(FStr *str, GNode *scope, VarE
 
 	if (strchr(str->str, '$') == NULL)
 		return;
-	(void)Var_Subst(str->str, scope, emode, &expanded);
+	expanded = Var_Subst(str->str, scope, emode);
 	/* TODO: handle errors */
 	FStr_Done(str);
 	*str = FStr_InitOwn(expanded);

Reply via email to