Subject: bin/30511: lex(1) generated files lint warnings
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <njoly@pasteur.fr>
List: netbsd-bugs
Date: 06/12/2005 19:32:01
>Number:         30511
>Category:       bin
>Synopsis:       lex(1) generated files lint warnings
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jun 12 19:32:00 +0000 2005
>Originator:     Nicolas Joly
>Release:        NetBSD 3.99.6
>Organization:
Institut Pasteur, Paris.
>Environment:
System: NetBSD cixy.dial.pasteur.fr 3.99.6 NetBSD 3.99.6 (CIXY) #11: Sun Jun 12 01:07:13 CEST 2005 njoly@cixy.dial.pasteur.fr:/local/src/NetBSD/obj/i386/sys/arch/i386/compile/CIXY i386
Architecture: i386
Machine: i386
>Description:
I noticed that lex(1) generated files show some warnings when checked with
lint(1) program.

njoly@cixy [squizz/lib]> lint -chapbxzF -DHAVE_CONFIG_H -I. **/*.c
[...]
./align/clustall.c:
align/clustall.c(1326): warning: constant in conditional context [161]
align/clustall.c(1670): warning: constant in conditional context [161]
align/clustall.c(795): warning: static variable yy_full_lp set but not used [307]
align/clustall.c(796): warning: static variable yy_full_state set but not used [307]
align/clustall.c(1582): warning: static function yyunput unused [236]
align/clustall.c(2095): warning: static function yy_flex_realloc unused [236]
[...]

with `%option noyywrap' set , `yywrap()' is defined to a constant which
lead to the first 2 warnings :

njoly@cixy [squizz/lib]> grep -n 'yywrap()' align/clustall.c
241:/* Flag which is used to allow yywrap()'s to do buffer switches
281:#define yywrap() 1
1326:                           if ( yywrap() )
1670:                                   if ( yywrap() )
1736:    * EOF (yywrap()) processing, but the only time this flag
1737:    * is looked at is after yywrap() is called, so it's safe

Since this part of code is not really user made, it should avoid as many
warnings as possible.

>How-To-Repeat:
use lint on lex generated files with `%option noyywrap'.
>Fix:
Don't know if this is the right fix, but it seems to give expected results.

Index: main.c
===================================================================
RCS file: /cvsroot/src/usr.bin/lex/main.c,v
retrieving revision 1.15
diff -u -r1.15 main.c
--- main.c	14 Jul 2003 11:36:49 -0000	1.15
+++ main.c	12 Jun 2005 18:33:39 -0000
@@ -949,7 +949,7 @@
 
 	if ( ! do_yywrap )
 		{
-		outn( "\n#define yywrap() 1" );
+		outn( "\n#define yywrap() (/*CONSTCOND*/1)" );
 		outn( "#define YY_SKIP_YYWRAP" );
 		}