🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.bugs.4bsd
Article #1211

lex bugs - with fixes

#1211
From: Mike Wescott
Date: Wed, 12 Oct 1988 22:28
114 lines
3566 bytes
The following patch fixes these bugs in lex:

1. If lex is invoked with multiple files on the command line, files after
	the first are not properly handled; every other one is opened until
	garbage is found as a filename.  Both the index (fptr) and the base
	pointer (sargv) were being incremented.

2. If a warning message is printed early enough, the file pointer fout may
	not be initialized, but warning() will do fflush(fout) anyway, and
	may dump core.

3. If there is no rules section in the input (a syntax error) processing
	continues, lex.yy.c won't compile, lex may dump core or it may
	terminate gracefully with exit value 0.  This patch errors out
	if EOF is detected before a rules section, exit value is 1 so
	as to make "make" unhappy.

4. The DEBUG code, not usually compiled in, has an anachronism, =+ is
	changed to +=

diff -cr lex.orig/main.c lex/main.c
*** lex.orig/main.c	Fri Sep 20 16:28:25 1985
--- lex/main.c	Wed Oct 12 17:52:56 1988
***************
*** 57,63 ****
  	if (argc > 1){
  		fin = fopen(argv[++fptr], "r");		/* open argv[1] */
  		sargc--;
- 		sargv++;
  		}
  	else fin = stdin;
  	if(fin == NULL)
--- 57,62 ----
diff -cr lex.orig/parser.y lex/parser.y
*** lex.orig/parser.y	Fri Sep 20 16:28:25 1985
--- lex/parser.y	Wed Oct 12 17:12:47 1988
***************
*** 429,434 ****
--- 429,435 ----
  				return(freturn(STR));
  				}
  			}
+ 			error("No rules section");
  		/* end of section one processing */
  		}
  	else if(sect == RULESECTION){		/* rules and actions */
diff -cr lex.orig/sub1.c lex/sub1.c
*** lex.orig/sub1.c	Mon Nov  4 13:43:26 1985
--- lex/sub1.c	Wed Oct 12 17:56:41 1988
***************
*** 67,73 ****
  	fprintf(errorf,s,p,d);
  	putc('\n',errorf);
  	fflush(errorf);
! 	fflush(fout);
  	fflush(stdout);
  	}
  index(a,s)
--- 67,74 ----
  	fprintf(errorf,s,p,d);
  	putc('\n',errorf);
  	fflush(errorf);
! 	if (fout != NULL)
! 		fflush(fout);
  	fflush(stdout);
  	}
  index(a,s)
***************
*** 379,385 ****
  	prev = pres;
  	c = pres = peek;
  	peek = pushptr > pushc ? *--pushptr : getc(fin);
! 	if(peek == EOF && sargc > 1){
  		fclose(fin);
  		fin = fopen(sargv[++fptr],"r");
  		if(fin == NULL)
--- 380,386 ----
  	prev = pres;
  	c = pres = peek;
  	peek = pushptr > pushc ? *--pushptr : getc(fin);
! 	while(peek == EOF && sargc > 1){
  		fclose(fin);
  		fin = fopen(sargv[++fptr],"r");
  		if(fin == NULL)
***************
*** 386,392 ****
  			error("Cannot open file %s",sargv[fptr]);
  		peek = getc(fin);
  		sargc--;
- 		sargv++;
  		}
  	if(c == EOF) {
  		eof = TRUE;
--- 387,392 ----
***************
*** 561,567 ****
  		default:
  			if(!printable(c)){
  				printf("\\%-3o",c);
! 				charc =+ 3;
  				}
  			else 
  				putchar(c);
--- 561,567 ----
  		default:
  			if(!printable(c)){
  				printf("\\%-3o",c);
! 				charc += 3;
  				}
  			else 
  				putchar(c);
-- 
	-Mike Wescott
	 mike.wescott@ncrcae.Columbia.NCR.COM
Technical Details
Message-ID: <1162@sauron.Columbia.NCR.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!gatech!hubcap!ncrcae!sauron!wescott
References: <5059@saturn.ucsc.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!gatech!hubcap!ncrcae!sauron!wescott
From: wescott@sauron.Columbia.NCR.COM (Mike Wescott)
Newsgroups: comp.bugs.4bsd,comp.bugs.sys5
Subject: lex bugs - with fixes
Summary: lex, bugs, fix
Keywords: lex
Message-ID: <1162@sauron.Columbia.NCR.COM>
Date: 12 Oct 88 22:28:47 GMT
References: <5059@saturn.ucsc.edu>
Reply-To: wescott@sauron.Columbia.NCR.COM (Mike Wescott)
Organization: Entry Level Systems Development, NCR Corp., Columbia, SC
Lines: 114