lex bugs - with fixes
Mike Wescott
wescott at sauron.Columbia.NCR.COM
Thu Oct 13 08:28:47 AEST 1988
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 at ncrcae.Columbia.NCR.COM
More information about the Comp.bugs.sys5
mailing list