Subject: Re: bin/29545: make(1) accepts .else* as .else
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: Robert Elz <kre@munnari.OZ.AU>
List: netbsd-bugs
Date: 03/02/2005 10:27:01
The following reply was made to PR bin/29545; it has been noted by GNATS.

From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@NetBSD.org
Cc: lukem@NetBSD.org, wiz@NetBSD.org
Subject: Re: bin/29545: make(1) accepts .else* as .else 
Date: Wed, 02 Mar 2005 17:22:03 +0700

     Date:        Sun, 27 Feb 2005 12:12:01 +0000 (UTC)
     From:        Thomas Klausner <wiz@NetBSD.org>
     Message-ID:  <20050227121201.17F4463B117@narn.netbsd.org>
 
   | make(1) accepts every string that starts with ".else" as ".else".
 
 Ugh - the code in there is truly disgusting.
 
   | >Fix:
   | Not provided.
 
 Here's a patch that "solves" that particular problem.   Make treats
 unknown .xxx's inside a conditional (that's being skipped) as simply
 noise
 
 	.if 0
 	. this is a comment...
 	.endif
 
 which is really pretty dumb - unrecognisable '.' lines should be
 errors whether inside a .if or outside it (this is quite different than
 attempting to evaluate the expression in a .if if the line is being
 skipped - that clearly shouldn't be done).
 
 That problem I haven't attempted to solve.
 
 The effect is that now
 
 	.if whatever
 	.elseif
 	.endif
 
 has a 50/50 chance of being reported as an error (will be if whatever
 is true, the whole thing will simply be ignored if whatever is false).
 
 At least that's the same now as .any-other-junk
 
 This patch is truly ugly (like the rest of the code in this part of make)
 but appears to work.   Apologies for the ugly indentation style.   I truly
 detest code written with a normal indent setting != 8.
 
 kre
 
 Index: cond.c
 ===================================================================
 RCS file: /cvsroot/NetBSD/src/usr.bin/make/cond.c,v
 retrieving revision 1.19.2.5
 diff -u -r1.19.2.5 cond.c
 --- cond.c	10 May 2004 15:44:10 -0000	1.19.2.5
 +++ cond.c	2 Mar 2005 09:58:29 -0000
 @@ -1275,7 +1275,8 @@
  	 * "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 && (line[0] == 's') && (line[1] == 'e') &&
 +		!isalpha(line[2]) && !isdigit(line[2])) {
  	    if (finalElse[condTop][skipIfLevel]) {
  		Parse_Error (PARSE_WARNING, "extra else");
  	    } else {