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): fix error message when parsing unknown...



details:   https://anonhg.NetBSD.org/src/rev/aba3ce1a1193
branches:  trunk
changeset: 942571:aba3ce1a1193
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Nov 10 20:52:28 2020 +0000

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

diffstat:

 usr.bin/make/cond.c                      |   6 +++---
 usr.bin/make/unit-tests/directive-if.exp |   8 ++++++--
 usr.bin/make/unit-tests/directive-if.mk  |  15 +++++++++++----
 3 files changed, 20 insertions(+), 9 deletions(-)

diffs (78 lines):

diff -r abcd454eb720 -r aba3ce1a1193 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Tue Nov 10 20:48:29 2020 +0000
+++ b/usr.bin/make/cond.c       Tue Nov 10 20:52:28 2020 +0000
@@ -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 @@
     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;
        }
diff -r abcd454eb720 -r aba3ce1a1193 usr.bin/make/unit-tests/directive-if.exp
--- a/usr.bin/make/unit-tests/directive-if.exp  Tue Nov 10 20:48:29 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-if.exp  Tue Nov 10 20:52:28 2020 +0000
@@ -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
diff -r abcd454eb720 -r aba3ce1a1193 usr.bin/make/unit-tests/directive-if.mk
--- a/usr.bin/make/unit-tests/directive-if.mk   Tue Nov 10 20:48:29 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-if.mk   Tue Nov 10 20:52:28 2020 +0000
@@ -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



Home | Main Index | Thread Index | Old Index