tech-toolchain archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
make: avoid segfault on parse error
While trying to trick make into handling something like:
VAR += ${${X:U0} > 0:?Use $X:}
I came accross the need for something like this.
Index: parse.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/parse.c,v
retrieving revision 1.147
diff -u -p -r1.147 parse.c
--- parse.c 6 Oct 2008 22:09:21 -0000 1.147
+++ parse.c 21 Oct 2008 18:19:01 -0000
@@ -392,7 +392,7 @@ ParseVErrorInternal(FILE *f, const char
(void)fprintf(f, "%s: \"", progname);
- if (*cfname != '/' && strcmp(cfname, "(stdin)") != 0) {
+ if (*cfname != '/' && *cfname != '(') {
char *cp;
const char *dir;
@@ -471,6 +471,15 @@ Parse_Error(int type, const char *fmt, .
va_list ap;
va_start(ap, fmt);
+ if (curFile == (IFile *)NIL) {
+ /* avoid segfault */
+ static IFile intFile = {
+ .fname = "(unknown)",
+ .lineno = 0,
+ .fd = -1,
+ };
+ curFile = &intFile;
+ }
ParseVErrorInternal(stderr, curFile->fname, curFile->lineno,
type, fmt, ap);
va_end(ap);
Index: unit-tests/cond1
===================================================================
RCS file: /cvsroot/src/usr.bin/make/unit-tests/cond1,v
retrieving revision 1.3
diff -u -p -r1.3 cond1
--- unit-tests/cond1 13 Apr 2004 16:06:23 -0000 1.3
+++ unit-tests/cond1 21 Oct 2008 18:19:01 -0000
@@ -100,3 +100,4 @@ all:
@echo "A='$A' B='$B' C='$C' o='$o,${o2}'"
@echo "Passed:${.newline} ${Ok:S/,/${.newline}/}"
@echo "${NUMBERS:@n@$n is ${("${PRIMES:M$n}" == ""):?not:}
prime${.newline}@}"
+ @echo "${"${NoSuch:U0}" > 0:?OK:No}"
Index: unit-tests/test.exp
===================================================================
RCS file: /cvsroot/src/usr.bin/make/unit-tests/test.exp,v
retrieving revision 1.25
diff -u -p -r1.25 test.exp
--- unit-tests/test.exp 15 May 2008 21:05:55 -0000 1.25
+++ unit-tests/test.exp 21 Oct 2008 18:19:01 -0000
@@ -20,6 +20,9 @@ Passed:
4 is not prime
5 is prime
+make: "(unknown)" line 0: warning: String comparison operator should be either
== or !=
+make: Bad conditional expression `"0" > 0' in "0" > 0?OK:No
+
UT_DOLLAR=This is $UT_FU
UT_FOO=foobar is fubar
UT_FU=fubar
Home |
Main Index |
Thread Index |
Old Index