Module Name: src
Committed By: rillig
Date: Mon Dec 14 21:56:17 UTC 2020
Modified Files:
src/usr.bin/make: cond.c
src/usr.bin/make/unit-tests: directive-endif.exp directive-endif.mk
Log Message:
make(1): error out if an '.endif' contains extraneous text
To generate a diff of this commit:
cvs rdiff -u -r1.224 -r1.225 src/usr.bin/make/cond.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-endif.exp
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/directive-endif.mk
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/cond.c
diff -u src/usr.bin/make/cond.c:1.224 src/usr.bin/make/cond.c:1.225
--- src/usr.bin/make/cond.c:1.224 Mon Dec 14 21:35:21 2020
+++ src/usr.bin/make/cond.c Mon Dec 14 21:56:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.224 2020/12/14 21:35:21 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.225 2020/12/14 21:56:17 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -94,7 +94,7 @@
#include "dir.h"
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: cond.c,v 1.224 2020/12/14 21:35:21 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.225 2020/12/14 21:56:17 rillig Exp $");
/*
* The parsing of conditional expressions is based on this grammar:
@@ -1162,7 +1162,10 @@ Cond_EvalLine(const char *line)
cpp_skip_hspace(&p);
if (IsEndif(p)) { /* It is an '.endif'. */
- /* TODO: check for extraneous <cond> */
+ if (p[5] != '\0') {
+ Parse_Error(PARSE_FATAL,
+ "The .endif directive does not take arguments.");
+ }
if (cond_depth == cond_min_depth) {
Parse_Error(PARSE_FATAL, "if-less endif");
Index: src/usr.bin/make/unit-tests/directive-endif.exp
diff -u src/usr.bin/make/unit-tests/directive-endif.exp:1.2 src/usr.bin/make/unit-tests/directive-endif.exp:1.3
--- src/usr.bin/make/unit-tests/directive-endif.exp:1.2 Mon Dec 14 20:57:31 2020
+++ src/usr.bin/make/unit-tests/directive-endif.exp Mon Dec 14 21:56:17 2020
@@ -1,4 +1,8 @@
-make: "directive-endif.mk" line 42: Unknown directive "endifx"
+make: "directive-endif.mk" line 18: The .endif directive does not take arguments.
+make: "directive-endif.mk" line 23: The .endif directive does not take arguments.
+make: "directive-endif.mk" line 33: The .endif directive does not take arguments.
+make: "directive-endif.mk" line 39: The .endif directive does not take arguments.
+make: "directive-endif.mk" line 45: Unknown directive "endifx"
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
Index: src/usr.bin/make/unit-tests/directive-endif.mk
diff -u src/usr.bin/make/unit-tests/directive-endif.mk:1.4 src/usr.bin/make/unit-tests/directive-endif.mk:1.5
--- src/usr.bin/make/unit-tests/directive-endif.mk:1.4 Mon Dec 14 20:57:31 2020
+++ src/usr.bin/make/unit-tests/directive-endif.mk Mon Dec 14 21:56:17 2020
@@ -1,7 +1,10 @@
-# $NetBSD: directive-endif.mk,v 1.4 2020/12/14 20:57:31 rillig Exp $
+# $NetBSD: directive-endif.mk,v 1.5 2020/12/14 21:56:17 rillig Exp $
#
# Tests for the .endif directive.
#
+# Since 2020-12-15, the .endif directive no longer accepts arguments.
+# The manual page had never allowed that, but the code didn't check it.
+#
# See also:
# Cond_EvalLine
@@ -10,13 +13,13 @@
.MAKEFLAGS: -dL
# Error: .endif does not take arguments
-# XXX: Missing error message
.if 0
+# Since 2020-12-15, complain about the extra text after the 'endif'.
.endif 0
# Error: .endif does not take arguments
-# XXX: Missing error message
.if 1
+# Since 2020-12-15, complain about the extra text after the 'endif'.
.endif 1
# Comments are allowed after an '.endif'.
@@ -25,14 +28,14 @@
# Only whitespace and comments are allowed after an '.endif', but nothing
# else.
-# XXX: Missing error message
.if 1
+# Since 2020-12-15, complain about the extra text after the 'endif'.
.endif0
# Only whitespace and comments are allowed after an '.endif', but nothing
# else.
-# XXX: Missing error message
.if 1
+# Since 2020-12-15, complain about the extra text after the 'endif'.
.endif/
# After an '.endif', no other letter must occur. This 'endifx' is not