Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make When parsing conditional tokens, make sure that...



details:   https://anonhg.NetBSD.org/src/rev/a3c9db64c626
branches:  trunk
changeset: 574479:a3c9db64c626
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Mar 01 04:34:55 2005 +0000

description:
When parsing conditional tokens, make sure that the token is followed by
a non-alpha character, so that .elsefoo is not parsed as .else leading
to confusion later.

diffstat:

 usr.bin/make/cond.c |  30 ++++++++++++++++++------------
 1 files changed, 18 insertions(+), 12 deletions(-)

diffs (120 lines):

diff -r de01e84cb476 -r a3c9db64c626 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Tue Mar 01 04:25:00 2005 +0000
+++ b/usr.bin/make/cond.c       Tue Mar 01 04:34:55 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.25 2005/02/16 15:11:52 christos Exp $       */
+/*     $NetBSD: cond.c,v 1.26 2005/03/01 04:34:55 christos Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: cond.c,v 1.25 2005/02/16 15:11:52 christos Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.26 2005/03/01 04:34:55 christos Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)cond.c     8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: cond.c,v 1.25 2005/02/16 15:11:52 christos Exp $");
+__RCSID("$NetBSD: cond.c,v 1.26 2005/03/01 04:34:55 christos Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -181,6 +181,12 @@
 static Boolean   skipLine = FALSE;     /* Whether the parse module is skipping
                                         * lines */
 
+static int
+istoken(const char *str, const char *tok, size_t len)
+{
+       return strncmp(str, tok, len) == 0 && !isalpha((unsigned char)str[len]);
+}
+
 /*-
  *-----------------------------------------------------------------------
  * CondPushBack --
@@ -841,7 +847,7 @@
                char    *arg;
                int     arglen;
 
-               if (strncmp (condExpr, "defined", 7) == 0) {
+               if (istoken(condExpr, "defined", 7)) {
                    /*
                     * Use CondDoDefined to evaluate the argument and
                     * CondGetArg to extract the argument from the 'function
@@ -854,7 +860,7 @@
                        condExpr -= 7;
                        goto use_default;
                    }
-               } else if (strncmp (condExpr, "make", 4) == 0) {
+               } else if (istoken(condExpr, "make", 4)) {
                    /*
                     * Use CondDoMake to evaluate the argument and
                     * CondGetArg to extract the argument from the 'function
@@ -867,7 +873,7 @@
                        condExpr -= 4;
                        goto use_default;
                    }
-               } else if (strncmp (condExpr, "exists", 6) == 0) {
+               } else if (istoken(condExpr, "exists", 6)) {
                    /*
                     * Use CondDoExists to evaluate the argument and
                     * CondGetArg to extract the argument from the
@@ -880,7 +886,7 @@
                        condExpr -= 6;
                        goto use_default;
                    }
-               } else if (strncmp(condExpr, "empty", 5) == 0) {
+               } else if (istoken(condExpr, "empty", 5)) {
                    /*
                     * Use Var_Parse to parse the spec in parens and return
                     * True if the resulting string is empty.
@@ -925,7 +931,7 @@
                        goto use_default;
                    }
                    break;
-               } else if (strncmp (condExpr, "target", 6) == 0) {
+               } else if (istoken(condExpr, "target", 6)) {
                    /*
                     * Use CondDoTarget to evaluate the argument and
                     * CondGetArg to extract the argument from the
@@ -938,7 +944,7 @@
                        condExpr -= 6;
                        goto use_default;
                    }
-               } else if (strncmp (condExpr, "commands", 8) == 0) {
+               } else if (istoken(condExpr, "commands", 8)) {
                    /*
                     * Use CondDoCommands to evaluate the argument and
                     * CondGetArg to extract the argument from the
@@ -1232,7 +1238,7 @@
     if (line[0] == 'e' && line[1] == 'l') {
        line += 2;
        isElse = TRUE;
-    } else if (strncmp (line, "endif", 5) == 0) {
+    } else if (istoken(line, "endif", 5)) {
        /*
         * End of a conditional section. If skipIfLevel is non-zero, that
         * conditional was skipped, so lines following it should also be
@@ -1264,7 +1270,7 @@
      * function is, etc. -- by looking in the table of valid "ifs"
      */
     for (ifp = ifs; ifp->form != (char *)0; ifp++) {
-       if (strncmp (ifp->form, line, ifp->formlen) == 0) {
+       if (istoken(ifp->form, line, ifp->formlen)) {
            break;
        }
     }
@@ -1275,7 +1281,7 @@
         * "else", it's a valid conditional whose value is the inverse
         * of the previous if we parsed.
         */
-       if (isElse && (line[0] == 's') && (line[1] == 'e')) {
+       if (isElse && istoken(line, "se", 2)) {
            if (finalElse[condTop][skipIfLevel]) {
                Parse_Error(PARSE_WARNING, "extra else");
            } else {



Home | Main Index | Thread Index | Old Index