From avn@any.ru  Sat Jun 23 04:33:15 2001
Return-Path: <avn@any.ru>
Received: from ajax2.sovam.com (ajax2.sovam.com [194.67.1.173])
	by hub.freebsd.org (Postfix) with ESMTP id 658D737B401
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 23 Jun 2001 04:33:15 -0700 (PDT)
	(envelope-from avn@any.ru)
Received: from ts9-a282.dial.sovam.com ([195.239.71.26]:1203 "EHLO srv2.any"
	ident: "TIMEDOUT" whoson: "-unregistered-" smtp-auth: <none> TLS-CIPHER:
	<none> TLS-PEER: <none>) by ajax2.sovam.com with ESMTP
	id <S424286AbRFWLdH>; Sat, 23 Jun 2001 15:33:07 +0400
Received: (from avn@localhost)
	by srv2.any (8.11.3/8.11.3) id f5NBVFS49472;
	Sat, 23 Jun 2001 15:31:15 +0400 (MSD)
	(envelope-from avn)
Message-Id: <200106231131.f5NBVFS49472@srv2.any>
Date: Sat, 23 Jun 2001 15:31:15 +0400 (MSD)
From: avn@any.ru
Reply-To: avn@any.ru
To: FreeBSD-gnats-submit@freebsd.org
Subject: lex(1) generated files fail to compile cleanly with -Wconversion
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         28364
>Category:       bin
>Synopsis:       [patch] flex(1) generated files fail to compile cleanly with -Wconversion
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    jkim
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jun 23 04:40:02 PDT 2001
>Closed-Date:    Mon Aug 26 22:59:17 UTC 2013
>Last-Modified:  Mon Aug 26 22:59:17 UTC 2013
>Originator:     Alexey V. Neyman
>Release:        FreeBSD 4.3-STABLE i386
>Organization:
http://www.any.ru/
>Environment:
System: FreeBSD srv2.any 4.3-STABLE FreeBSD 4.3-STABLE #4: Thu Jun 14 12:25:16 MSD 2001 toor@srv2.any:/usr2/obj/usr2/src/sys/SRV2 i386

>Description:
lex(1) generates files which do not pass -Wconversion either with -ansi or
without it. This means, they won't compile under BDECFLAGS.

>How-To-Repeat:
--- Makefile ---
SRCS = a.l
PROG = a
NOMAN = yes
NOOBJ = yes
CFLAGS = -Wconversion -ansi -pedantic

.include <bsd.prog.mk>
--- a.l ---
%option noyywrap
%{
#include <stdio.h>
%}
%%
.		{ }
%%
int main(void)
{
	return 0;
}
--- end ---
produce the following warnings:
a.l: In function `yylex':
a.l:7: warning: passing arg 2 of `fwrite' as unsigned due to prototype
a.l: In function `yy_get_next_buffer':
a.l:246: warning: passing arg 3 of `fread' as unsigned due to prototype

Also, these warnings point to 'a.l' which is erroneous (obviously, a.l
does not have line 246 :).
>Fix:
The patch below makes this sample to go cleanly under -Wconversion with
or without -ansi.

--- flex.skl.orig	Sat Jun 23 15:15:38 2001
+++ flex.skl	Sat Jun 23 15:15:38 2001
@@ -104,7 +104,7 @@
 
 typedef struct yy_buffer_state *YY_BUFFER_STATE;
 
-extern int yyleng;
+extern size_t yyleng;
 %-
 extern FILE *yyin, *yyout;
 %*
@@ -228,7 +228,7 @@
 static int yy_n_chars;		/* number of characters read into yy_ch_buf */
 
 
-int yyleng;
+size_t yyleng;
 
 /* Points to current character in buffer. */
 static char *yy_c_buf_p = (char *) 0;
@@ -788,7 +788,7 @@
 
 	else
 		{
-		int num_to_read =
+		size_t num_to_read =
 			yy_current_buffer->yy_buf_size - number_to_move - 1;
 
 		while ( num_to_read <= 0 )
--- gen.c.orig	Sat Jun 23 15:15:38 2001
+++ gen.c	Sat Jun 23 15:15:38 2001
@@ -1070,11 +1070,11 @@
 	if ( yymore_used && ! yytext_is_array )
 		{
 		indent_puts( "yytext_ptr -= yy_more_len; \\" );
-		indent_puts( "yyleng = (int) (yy_cp - yytext_ptr); \\" );
+		indent_puts( "yyleng = (size_t) (yy_cp - yytext_ptr); \\" );
 		}
 
 	else
-		indent_puts( "yyleng = (int) (yy_cp - yy_bp); \\" );
+		indent_puts( "yyleng = (size_t) (yy_cp - yy_bp); \\" );
 
 	/* Now also deal with copying yytext_ptr to yytext if needed. */
 	skelout();
@@ -1341,7 +1341,8 @@
 			outn(
 			"\tif ( yy_current_buffer->yy_is_interactive ) \\" );
 			outn( "\t\t{ \\" );
-			outn( "\t\tint c = '*', n; \\" );
+			outn( "\t\tint c = '*'; \\");
+			outn( "\t\tsize_t n; \\" );
 			outn( "\t\tfor ( n = 0; n < max_size && \\" );
 	outn( "\t\t\t     (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\" );
 			outn( "\t\t\tbuf[n] = (char) c; \\" );
>Release-Note:
>Audit-Trail:

From: Ruslan Ermilov <ru@FreeBSD.ORG>
To: avn@any.ru
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/28364: lex(1) generated files fail to compile cleanly with -Wconversion
Date: Sat, 23 Jun 2001 14:57:57 +0300

 Hello Alexey!
 
 Could you please try to coordinate the acceptance of your
 patch with the Flex maintainers?  (See lex/README.)
 
 This way, we could import your fix as a vendor fix onto
 the LBL branch.
 
 
 Thanks,
 -- 
 Ruslan Ermilov		Oracle Developer/DBA,
 ru@sunbay.com		Sunbay Software AG,
 ru@FreeBSD.org		FreeBSD committer,
 +380.652.512.251	Simferopol, Ukraine
 
 http://www.FreeBSD.org	The Power To Serve
 http://www.oracle.com	Enabling The Information Age

From: bruce@cran.org.uk
To: bug-followup@FreeBSD.org, avn@any.ru
Cc:  
Subject: Re: bin/28364: flex(1) generated files fail to compile cleanly with -Wconversion
Date: Mon, 14 Jul 2008 12:34:01 +0100

 I suspect this bug has already been fixed in newer releases of flex: I
 know I've come across similar bugs in 2.5.4 which are fixed even in
 2.5.33 (the newest being 2.5.35).  Is there any chance that a newer
 version could be imported into FreeBSD?
 
 -- 
 Bruce Cran
Responsible-Changed-From-To: freebsd-bugs->bapt 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Sat Jan 21 20:56:25 UTC 2012 
Responsible-Changed-Why:  
please don't hate me 

http://www.freebsd.org/cgi/query-pr.cgi?pr=28364 
Responsible-Changed-From-To: bapt->jkim 
Responsible-Changed-By: bapt 
Responsible-Changed-When: Sun Aug 25 10:14:08 UTC 2013 
Responsible-Changed-Why:  
Over to new flex maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=28364 
State-Changed-From-To: open->closed 
State-Changed-By: jkim 
State-Changed-When: Mon Aug 26 22:32:23 UTC 2013 
State-Changed-Why:  
It is very easy to fix for WARNS=6, aka "BDECFLAGS". 

--- a.l 
+++ a.l 
@@ -1,4 +1,4 @@ 
-%option noyywrap 
+%option noyywrap noinput nounput 
%{ 
#include <stdio.h> 
%} 

http://www.freebsd.org/cgi/query-pr.cgi?pr=28364 
>Unformatted:
