Module Name: src
Committed By: rillig
Date: Tue Jan 19 17:57:07 UTC 2021
Modified Files:
src/usr.bin/make: cond.c
Log Message:
make(1): fix possible return values for CondParser_Term
The invalid return values didn't do any harm since CondParser_Factor and
CondParser_Expr passed them through, and CondParser_Eval carefully
checks for TOK_TRUE or TOK_FALSE and treats everything else as an error.
No change in observable behavior since there is no debug logging in that
part of the code.
To generate a diff of this commit:
cvs rdiff -u -r1.236 -r1.237 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.236 src/usr.bin/make/cond.c:1.237
--- src/usr.bin/make/cond.c:1.236 Tue Jan 19 17:49:13 2021
+++ src/usr.bin/make/cond.c Tue Jan 19 17:57:07 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.236 2021/01/19 17:49:13 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.237 2021/01/19 17:57:07 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
#include "dir.h"
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: cond.c,v 1.236 2021/01/19 17:49:13 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.237 2021/01/19 17:57:07 rillig Exp $");
/*
* The parsing of conditional expressions is based on this grammar:
@@ -924,14 +924,10 @@ CondParser_Term(CondParser *par, Boolean
Token t;
t = CondParser_Token(par, doEval);
+ if (t == TOK_TRUE || t == TOK_FALSE)
+ return t;
- if (t == TOK_EOF) {
- /*
- * If we reached the end of the expression, the expression
- * is malformed...
- */
- t = TOK_ERROR;
- } else if (t == TOK_LPAREN) {
+ if (t == TOK_LPAREN) {
/*
* T -> ( E )
*/
@@ -948,13 +944,10 @@ CondParser_Term(CondParser *par, Boolean
} else if (t == TOK_FALSE) {
t = TOK_TRUE;
}
- }
+ } else
+ return TOK_ERROR;
- /*
- * FIXME: Can at least return TOK_AND, TOK_OR, TOK_RPAREN, maybe
- * others as well.
- */
- /* TODO: assert(t == TOK_ERROR); */
+ assert(t == TOK_TRUE || t == TOK_FALSE || t == TOK_ERROR);
return t;
}