Module Name: src
Committed By: rillig
Date: Thu Dec 9 22:25:58 UTC 2021
Modified Files:
src/usr.bin/make: cond.c
Log Message:
make: avoid recursion in CondParser_Or
Previously, a long chain of '1 || 1 || 1 || 1 || ...' led to a deep
recursion. Furhermore, the code didn't match the grammar on superficial
reading: the grammar said "or || and", the code said "and || or".
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.282 -r1.283 src/usr.bin/make/cond.c
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.282 src/usr.bin/make/cond.c:1.283
--- src/usr.bin/make/cond.c:1.282 Thu Dec 9 20:13:09 2021
+++ src/usr.bin/make/cond.c Thu Dec 9 22:25:58 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.282 2021/12/09 20:13:09 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.283 2021/12/09 22:25:58 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,12 +95,11 @@
#include "dir.h"
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: cond.c,v 1.282 2021/12/09 20:13:09 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.283 2021/12/09 22:25:58 rillig Exp $");
/*
* The parsing of conditional expressions is based on this grammar:
- * Or -> And
- * Or -> Or '||' And
+ * Or -> And ('||' And)*
* And -> Term
* And -> And '&&' Term
* Term -> Function '(' Argument ')'
@@ -1002,26 +1001,22 @@ CondParser_And(CondParser *par, bool doE
}
/*
- * Or -> And
- * Or -> Or '||' And
+ * Or -> And ('||' And)*
*/
static CondResult
CondParser_Or(CondParser *par, bool doEval)
{
- CondResult res;
+ CondResult res, r;
Token op;
- res = CondParser_And(par, doEval);
- if (res == CR_ERROR)
+ if ((res = CondParser_And(par, doEval)) == CR_ERROR)
return CR_ERROR;
- op = CondParser_Token(par, doEval);
- if (op == TOK_OR) {
- if (res == CR_FALSE)
- return CondParser_Or(par, doEval);
- if (CondParser_Or(par, false) == CR_ERROR)
+ while ((op = CondParser_Token(par, res == CR_FALSE)) == TOK_OR) {
+ if ((r = CondParser_And(par, res == CR_FALSE)) == CR_ERROR)
return CR_ERROR;
- return res;
+ if (r == CR_TRUE)
+ res = CR_TRUE;
}
CondParser_PushBack(par, op);