Module Name:    src
Committed By:   rillig
Date:           Tue Nov 10 20:52:28 UTC 2020

Modified Files:
        src/usr.bin/make: cond.c
        src/usr.bin/make/unit-tests: directive-if.exp directive-if.mk

Log Message:
make(1): fix error message when parsing unknown .if (since 2005-05-01)


To generate a diff of this commit:
cvs rdiff -u -r1.201 -r1.202 src/usr.bin/make/cond.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/directive-if.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/directive-if.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.201 src/usr.bin/make/cond.c:1.202
--- src/usr.bin/make/cond.c:1.201	Tue Nov 10 20:44:18 2020
+++ src/usr.bin/make/cond.c	Tue Nov 10 20:52:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.201 2020/11/10 20:44:18 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.202 2020/11/10 20:52:28 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -93,7 +93,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.201 2020/11/10 20:44:18 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.202 2020/11/10 20:52:28 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -1170,7 +1170,7 @@ Cond_EvalLine(const char *line)
     for (ifp = ifs;; ifp++) {
 	if (ifp->form == NULL)
 	    return COND_INVALID;
-	if (is_token(ifp->form, line, ifp->formlen)) {
+	if (is_token(line, ifp->form, ifp->formlen)) {
 	    line += ifp->formlen;
 	    break;
 	}

Index: src/usr.bin/make/unit-tests/directive-if.exp
diff -u src/usr.bin/make/unit-tests/directive-if.exp:1.2 src/usr.bin/make/unit-tests/directive-if.exp:1.3
--- src/usr.bin/make/unit-tests/directive-if.exp:1.2	Tue Nov 10 20:44:18 2020
+++ src/usr.bin/make/unit-tests/directive-if.exp	Tue Nov 10 20:52:28 2020
@@ -1,7 +1,11 @@
 make: "directive-if.mk" line 10: 0 evaluates to false.
 make: "directive-if.mk" line 14: 1 evaluates to true.
-make: "directive-if.mk" line 30: Malformed conditional (x 123)
-make: "directive-if.mk" line 37: Malformed conditional ()
+make: "directive-if.mk" line 37: Unknown directive "ifx"
+make: "directive-if.mk" line 38: Unknown directive "error"
+make: "directive-if.mk" line 39: if-less else
+make: "directive-if.mk" line 40: Unknown directive "error"
+make: "directive-if.mk" line 41: if-less endif
+make: "directive-if.mk" line 44: Malformed conditional ()
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/directive-if.mk
diff -u src/usr.bin/make/unit-tests/directive-if.mk:1.3 src/usr.bin/make/unit-tests/directive-if.mk:1.4
--- src/usr.bin/make/unit-tests/directive-if.mk:1.3	Tue Nov 10 20:44:18 2020
+++ src/usr.bin/make/unit-tests/directive-if.mk	Tue Nov 10 20:52:28 2020
@@ -1,4 +1,4 @@
-# $NetBSD: directive-if.mk,v 1.3 2020/11/10 20:44:18 rillig Exp $
+# $NetBSD: directive-if.mk,v 1.4 2020/11/10 20:52:28 rillig Exp $
 #
 # Tests for the .if directive.
 
@@ -19,14 +19,21 @@
 # There is no '.ifx'.
 #
 # The commit from 2005-05-01 intended to detect this situation, but it failed
-# to do this since the call to is_token has its arguments switched.  They are
-# expected as (str, token, token_len) but are actually passed as (token, str,
+# to do this since the call to is_token had its arguments switched.  They were
+# expected as (str, token, token_len) but were actually passed as (token, str,
 # token_len).  This made is_token return true even if the directive was
-# directly followed by alphanumerical characters.
+# directly followed by alphanumerical characters, which was wrong.  The
+# typical cases produced an error message such as "Malformed conditional
+# (x 123)", while the intended error message was "Unknown directive".
 #
 # Back at that time, the commits only modified the main code but did not add
 # the corresponding unit tests.  This allowed the bug to hide for more than
 # 15 years.
+#
+# Since 2020-11-10, the correct error message is produced.  The '.ifx' is no
+# longer interpreted as a variant of '.if', therefore the '.error' and '.else'
+# are interpreted as ordinary directives, producing the error messages
+# "if-less else" and "if-less endif".
 .ifx 123
 .  error
 .else

Reply via email to