Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 23 Jun 2001 15:31:15 +0400 (MSD)
From:      avn@any.ru
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/28364: lex(1) generated files fail to compile cleanly with -Wconversion
Message-ID:  <200106231131.f5NBVFS49472@srv2.any>

next in thread | raw e-mail | index | archive | help

>Number:         28364
>Category:       bin
>Synopsis:       lex(1) generated files fail to compile cleanly with -Wconversion
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jun 23 04:40:02 PDT 2001
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200106231131.f5NBVFS49472>