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): trust that Var_Subst never returns NULL
details: https://anonhg.NetBSD.org/src/rev/0d0f3eadc3fe
branches: trunk
changeset: 943264:0d0f3eadc3fe
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Aug 29 13:16:54 2020 +0000
description:
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.
diffstat:
usr.bin/make/main.c | 19 +++++++------------
usr.bin/make/make.c | 8 ++++----
usr.bin/make/meta.c | 16 ++++++----------
usr.bin/make/suff.c | 9 +++++----
usr.bin/make/var.c | 23 ++++++++++-------------
5 files changed, 32 insertions(+), 43 deletions(-)
diffs (247 lines):
diff -r fd3fecee7b61 -r 0d0f3eadc3fe usr.bin/make/main.c
--- a/usr.bin/make/main.c Sat Aug 29 13:04:30 2020 +0000
+++ b/usr.bin/make/main.c Sat Aug 29 13:16:54 2020 +0000
@@ -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 @@
#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 @@
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 @@
}
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);
/*
diff -r fd3fecee7b61 -r 0d0f3eadc3fe usr.bin/make/make.c
--- a/usr.bin/make/make.c Sat Aug 29 13:04:30 2020 +0000
+++ b/usr.bin/make/make.c Sat Aug 29 13:16:54 2020 +0000
@@ -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 @@
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)
diff -r fd3fecee7b61 -r 0d0f3eadc3fe usr.bin/make/meta.c
--- a/usr.bin/make/meta.c Sat Aug 29 13:04:30 2020 +0000
+++ b/usr.bin/make/meta.c Sat Aug 29 13:16:54 2020 +0000
@@ -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 @@
{
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 @@
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 @@
"/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}
diff -r fd3fecee7b61 -r 0d0f3eadc3fe usr.bin/make/suff.c
--- a/usr.bin/make/suff.c Sat Aug 29 13:04:30 2020 +0000
+++ b/usr.bin/make/suff.c Sat Aug 29 13:16:54 2020 +0000
@@ -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 @@
}
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 @@
*/
free(cp);
}
+
if (DEBUG(SUFF)) {
fprintf(debug_file, "\n");
}
diff -r fd3fecee7b61 -r 0d0f3eadc3fe usr.bin/make/var.c
--- a/usr.bin/make/var.c Sat Aug 29 13:04:30 2020 +0000
+++ b/usr.bin/make/var.c Sat Aug 29 13:16:54 2020 +0000
@@ -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_GLOBAL, VARE_WANTRES);
}
- if (TRUE) {
+ {
Var *v;
char **av;
char *as;
@@ -1464,14 +1464,12 @@
VAR_DEBUG("ModifyWord_Loop: in \"%s\", replace \"%s\" with \"%s\" "
"to \"%s\"\n",
- word, args->tvar, args->str, s ? s : "(null)");
-
- 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);
- }
+ word, args->tvar, args->str, 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 @@
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;
Home |
Main Index |
Thread Index |
Old Index