Subject: cpp "too much defining" under lint
Index:	lib/cpp 2.11BSD

Description:
	cpp can run out of 'define' buffer space when processing
	files for 'lint' (using the -C option).

Repeat-By:
	Attempt to 'lint' C-Kermit(5A) or the kernel (after having
	assembled 'lint' from the posted patches).  Note the "too much
	defining" error.

Fix:
	cpp normally can process the C-Kermit(5A) and kernel sources.
	The problem when being run by 'lint' is that the -C flag is
	used preventing cpp from deleting comments.  Comments are
	not deleted when cpp is run by lint so that the special
	comments "/* NOTREACHED */", "/* ARGSUSED */", etc are not
	removed.

	Many of the include files have much defining of the form:

		"#define MAGIC_COOKIE 1	/* this is a magic cookie for foo */"

	Too much defining of that type exhausts cpp's buffer space.

	The fix is to strip comments within "#define" statements even
	if the -C flag is being used.  

	Out of the thousands of .c and .h files in the system exactly 0
	(zero) have any of the special lint comments within a #define 
	statement.

	The string buffer size is increased slightly from 38k to 39k
	(and the comment repaired).  Also a buffer for the "stdout"
	is allocated on the stack.  This insures that the output will
	always be buffered and not depend on malloc space being available.
	Sccs strings were commented out saving additional D space.

	cd /usr/src/lib/cpp; patch < this_patch_file; make
-------------------------------------------------------------------------
*** Makefile.old	Mon Dec 26 17:17:04 1988
--- Makefile	Wed Aug  7 08:21:56 1991
***************
*** 21,27 ****
  cpy.c : cpy.y
  	yacc cpy.y
  	../pcc/:yyfix yyexca yyact yypact yypgo yyr1 yyr2 yychk yydef
! 	mv y.tab.c cpy.c
  
  cpy.o :	cpy.c yylex.c
  
--- 21,28 ----
  cpy.c : cpy.y
  	yacc cpy.y
  	../pcc/:yyfix yyexca yyact yypact yypgo yyr1 yyr2 yychk yydef
! 	fgrep -v "static char yaccpar_sccsid" y.tab.c >cpy.c
! 	rm -f y.tab.c
  
  cpy.o :	cpy.c yylex.c
  
*** cpp.c.old	Mon Dec 26 17:18:12 1988
--- cpp.c	Tue Aug 13 10:31:47 1991
***************
*** 1,6 ****
! #ifndef lint
! static char sccsid[] = "@(#)cpp.c	1.8 5/16/84";
! #endif lint
  
  #ifdef FLEXNAMES
  #define	NCPS	128
--- 1,4 ----
! /* static char sccsid[] = "@(#)cpp.c	1.8 5/16/84"; */
  
  #ifdef FLEXNAMES
  #define	NCPS	128
***************
*** 112,118 ****
  char buffer[NCPS+BUFSIZ+BUFSIZ+NCPS];
  
  #ifdef pdp11
! # define SBSIZE ((unsigned)0112160)	/* PDP compiler doesn't like 41000 */
  short	sbff[SBSIZE/2];
  # define sbf ((char *)sbff)
  #else !pdp11
--- 110,116 ----
  char buffer[NCPS+BUFSIZ+BUFSIZ+NCPS];
  
  #ifdef pdp11
! # define SBSIZE ((unsigned)0114130)	/* PDP compiler doesn't like 39024 */
  short	sbff[SBSIZE/2];
  # define sbf ((char *)sbff)
  #else !pdp11
***************
*** 639,644 ****
--- 637,644 ----
  	char *oldval,*oldsavch;
  	char *formal[MAXFRM]; /* formal[n] is name of nth formal */
  	char formtxt[BUFSIZ]; /* space for formal names */
+ 	int spasscom = passcom;
+ 	passcom = 0;		/* strip comments from defines to save space */
  
  	if (savch>sbf+SBSIZE-BUFSIZ) {pperror("too much defining"); return(p);}
  	oldsavch=savch; /* to reclaim space if redefinition */
***************
*** 719,725 ****
  			np->value=psav-1;
  		} else psav=oldsavch; /* identical redef.; reclaim space */
  	} else np->value=psav-1;
! 	--flslvl; inp=pin; savch=psav; return(p);
  }
  
  #define fasscan() ptrtab=fastab+COFF
--- 719,725 ----
  			np->value=psav-1;
  		} else psav=oldsavch; /* identical redef.; reclaim space */
  	} else np->value=psav-1;
! 	--flslvl; inp=pin; savch=psav; passcom = spasscom; return(p);
  }
  
  #define fasscan() ptrtab=fastab+COFF
***************
*** 1013,1019 ****
  {
  	register int i,c;
  	register char *p;
! 	char *tf,**cp2;
  
  # if gcos
  	if (setjmp(env)) return (exfail);
--- 1013,1019 ----
  {
  	register int i,c;
  	register char *p;
! 	char *tf,**cp2, obuf[BUFSIZ];
  
  # if gcos
  	if (setjmp(env)) return (exfail);
***************
*** 1147,1157 ****
--- 1147,1159 ----
  		if (tf!=(char *)0)
  			infile = tf + 1;
  		mout=fout;
+ 		setbuf(mout, (char *)NULL);
  		if (NULL==(fout=fopen("/dev/null", "w"))) {
  			pperror("Can't open /dev/null");
  			exit(8);
  		}
  	}
+ 	setbuf(fout, obuf);
  	fins[ifno]=fin;
  	exfail = 0;
  		/* after user -I files here are the standard include libraries */
*** yylex.c.old	Tue Oct 21 01:23:52 1986
--- yylex.c	Wed Aug  7 08:13:34 1991
***************
*** 1,6 ****
! #ifndef lint
! static char sccsid[] = "@(#)yylex.c	1.3 7/1/83";
! #endif lint
  
  #define isid(a)  ((fastab+COFF)[a]&IB)
  #define IB 1
--- 1,4 ----
! /* static char sccsid[] = "@(#)yylex.c	1.3 7/1/83"; */
  
  #define isid(a)  ((fastab+COFF)[a]&IB)
  #define IB 1
