[comp.bugs.4bsd] lex dumps core on empty input

wendt@arizona.edu (Alan Lee Wendt) (11/20/88)

lex < /dev/null dumps core.

An easy workaround is "don't do that"!

Alan W.

dave@cs.wisc.edu (Dave Cohrs) (11/21/88)

In article <7995@megaron.arizona.edu> wendt@arizona.edu (Alan Lee Wendt) writes:
>lex < /dev/null dumps core.

Here's simple fix for the 4.3bsd lex; your line numbers may
vary:

*** /tmp/,RCSt1a06426	Sun Nov 20 12:30:34 1988
--- lmain.c	Sun Nov 20 12:18:51 1988
***************
*** 69,74 ****
--- 69,77 ----
  	sp += slength("INITIAL") + 1;
  	sname[1] = 0;
  	if(yyparse(0)) exit(1);	/* error return code */
+ #ifdef UW
+ 	if(fout == NULL) exit(1); /* never opened output; so just quit */
+ #endif UW
  		/* may be disposed of: def, subs, dchar */
  	free1core();
  		/* may be gotten: tmpstat, foll, positions, gotof, nexts, nchar, state, atable, sfall, cpackflg */

*** /tmp/,RCSt1a06437	Sun Nov 20 12:31:17 1988
--- parser.y	Sun Nov 20 12:30:23 1988
***************
*** 241,256 ****
--- 241,272 ----
  						sectbegin = TRUE;
  						i = treesize*(sizeof(*name)+sizeof(*left)+
  							sizeof(*right)+sizeof(*nullstr)+sizeof(*parent))+ALITTLEEXTRA;
+ #ifdef UW
+ 						/* bad typing; morons! */
+ 						xp = myalloc(i,1);
+ 						if(xp == 0)
+ 							error("Too little core for parse tree");
+ 						p = xp;
+ #else
  						c = myalloc(i,1);
  						if(c == 0)
  							error("Too little core for parse tree");
  						p = c;
+ #endif UW
  						cfree(p,i,1);
+ #ifdef UW
+ 						name = (int*) myalloc(treesize,sizeof(*name));
+ 						left = (int*) myalloc(treesize,sizeof(*left));
+ 						right = (int*) myalloc(treesize,sizeof(*right));
+ 						nullstr = myalloc(treesize,sizeof(*nullstr));
+ 						parent = (int*) myalloc(treesize,sizeof(*parent));
+ #else
  						name = myalloc(treesize,sizeof(*name));
  						left = myalloc(treesize,sizeof(*left));
  						right = myalloc(treesize,sizeof(*right));
  						nullstr = myalloc(treesize,sizeof(*nullstr));
  						parent = myalloc(treesize,sizeof(*parent));
+ #endif UW
  						if(name == 0 || left == 0 || right == 0 || parent == 0 || nullstr == 0)
  							error("Too little core for parse tree");
  						return(freturn(DELIM));
***************
*** 678,683 ****
--- 694,705 ----
  			}
  		}
  	/* section three */
+ #ifdef UW
+ 	/* EOF before we did any real processing! */
+ 	if (!lgatflg) {
+ 		return(freturn(0));
+ 	}
+ #endif UW
  	ptail();
  # ifdef DEBUG
  	if(debug)
--
Dave Cohrs
+1 608 262-6617                        UW-Madison Computer Sciences Department
dave@cs.wisc.edu                       ...!{harvard,rutgers,ucbvax}!uwvax!dave