summaryrefslogtreecommitdiff
path: root/usr.bin/make/varmodifiers.c
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2000-07-17 23:26:52 +0000
committerMarc Espie <espie@cvs.openbsd.org>2000-07-17 23:26:52 +0000
commit3c401a2d5fb6a3843fd30b5a061d05a2243b0234 (patch)
tree78ae558ab25a610d8e4d5c2d1748f1dbe736283b /usr.bin/make/varmodifiers.c
parent49d2ed20aec6088b1c4a1de3319710ee9c75f7b0 (diff)
- let VarModifiers_Apply accept NULL string gracefully,
- simplify Var_Parse: use varfind, then leverage on the result to recognize `special case' dynamic parsing. VarModifiers_Apply need to be called on NULL strings, to be able to parse modifiers applied to non-existent variables. (Alternately, we could call VarModifiers_Apply on a dummy string, but this is less efficient).
Diffstat (limited to 'usr.bin/make/varmodifiers.c')
-rw-r--r--usr.bin/make/varmodifiers.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/usr.bin/make/varmodifiers.c b/usr.bin/make/varmodifiers.c
index 718651855ab..2100d26711b 100644
--- a/usr.bin/make/varmodifiers.c
+++ b/usr.bin/make/varmodifiers.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: varmodifiers.c,v 1.1 2000/07/17 23:09:06 espie Exp $ */
+/* $OpenBSD: varmodifiers.c,v 1.2 2000/07/17 23:26:51 espie Exp $ */
/* $NetBSD: var.c,v 1.18 1997/03/18 19:24:46 christos Exp $ */
/*
@@ -783,6 +783,9 @@ VarModify (str, modProc, datum)
char *as; /* word list memory */
int ac, i;
+ if (str == NULL)
+ return NULL;
+
Buf_Init(&buf, 0);
addSpace = FALSE;
@@ -935,7 +938,7 @@ VarModifiers_Apply(str, ctxt, err, freePtr, start, endc, lengthPtr)
char termc; /* Character which terminated scan */
if (DEBUG(VAR))
- printf("Applying :%c to \"%s\"\n", *tstr, str);
+ printf("Applying :%c to \"%s\"\n", *tstr, str ? str : "");
switch (*tstr) {
case 'N':
case 'M':
@@ -1122,7 +1125,7 @@ VarModifiers_Apply(str, ctxt, err, freePtr, start, endc, lengthPtr)
case 's':
if (tstr[1] == 'h' && (tstr[2] == endc || tstr[2] == ':')) {
char *err;
- newStr = Cmd_Exec(str, &err);
+ newStr = str ? Cmd_Exec(str, &err) : NULL;
if (err)
Error(err, str);
cp = tstr + 2;
@@ -1210,12 +1213,12 @@ VarModifiers_Apply(str, ctxt, err, freePtr, start, endc, lengthPtr)
}
}
if (DEBUG(VAR))
- printf("Result is \"%s\"\n", newStr);
+ printf("Result is \"%s\"\n", newStr != NULL ? newStr : "");
if (*freePtr)
free(str);
str = newStr;
- if (str != var_Error)
+ if (str != var_Error && str != NULL)
*freePtr = TRUE;
else
*freePtr = FALSE;
@@ -1257,6 +1260,9 @@ VarQuote(str)
/* This should cover most shells :-( */
static char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~";
+ if (str == NULL)
+ return NULL;
+
Buf_Init(&buf, MAKE_BSIZE);
for (; *str; str++) {
if (strchr(meta, *str) != NULL)