*BSD News Article 70843


Return to BSD News archive

Newsgroups: comp.bugs.2bsd
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.rmit.EDU.AU!news.unimelb.EDU.AU!munnari.OZ.AU!news.hawaii.edu!news.uoregon.edu!newsfeed.internetmci.com!salliemae!europa.chnt.gtegsc.com!wlbr!moe!sms
From: sms@moe.2bsd.com (Steven M. Schultz)
Subject: cpp can only hand 20 -D/-U options, c2 fails ungracefully (#324)
Organization: 2BSD, Simi Valley CA USA
Message-ID: <DswnKp.pA@moe.2bsd.com>
Date: Wed, 12 Jun 1996 20:58:01 GMT
Lines: 129

Subject: cpp can only hand 20 -D/-U options, c2 fails ungracefully (#324)
Index:	lib/cpp/cpp.c,lib/c2/c20.c 2.11BSD

Description:
	The C preprocessor (/lib/cpp) has a limit of 20 -D options that can
	be specified on the command line.  In rare cases (compiling highly
	parameterized programs such a C-Kermit) this is too low.

	When faced with pathological input The C optimizer (/lib/c2) runs
	out of memory and core dumps without an error message.

Repeat-By:
	Attempt to compile C-Kermit 6A(192).

Fix:
	Each additional option (-D or -U) to the preprocessor takes 4 bytes
	of data space plus the string storage in the environment.  There was
	room for 40 additonal bytes in the cpp program itself.  The environment
	has several hundred (perhaps even 1kb or more) bytes free which is
	enough to handle 10 additional "average" sized strings with ease.

	The C optimizer was *trying* to print out a message saying "out of
	memory".  But unfortunately it was using 'stderr' for the first time
	and malloc() failed when called from the stdio routine 'fprintf'.
	The fix was to add a 'setbuffer' call in main() and assign an 80
	byte buffer on the stack to "stderr" immediately upon c2 start up.

	To apply this update cut where indicated, saving to a file (/tmp/324).
	Then:

		patch -p0 < /tmp/324
		cd /usr/src/lib/cpp
		make
		make install
		make clean

		cd /usr/src/lib/c2
		make
		make install
		make clean

	This and previous updates are available via anonymous FTP to either
	FTP.IIPO.GTEGSC.COM or FTP.2BSD.COM in /pub/2.11BSD

-------------------------cut here--------------------
*** /usr/src/lib/c2/c20.c.old	Tue Oct 29 14:09:09 1991
--- /usr/src/lib/c2/c20.c	Wed Jun 12 11:09:34 1996
***************
*** 1,5 ****
--- 1,7 ----
  /*
   *	 C object code improver
+  *
+  *	@(#)	c20.c	2.0	(2.11BSD)	1996/6/12
   */
  
  #include "c2.h"
***************
*** 76,82 ****
  	int nflag;
  	char	stspace[NSTK],
  		buf1[BUFSIZ],
! 		buf2[BUFSIZ];
  
  	if (argc>1 && argv[1][0]=='+') {
  		argc--;
--- 78,85 ----
  	int nflag;
  	char	stspace[NSTK],
  		buf1[BUFSIZ],
! 		buf2[BUFSIZ],
! 		stderrbuf[80];
  
  	if (argc>1 && argv[1][0]=='+') {
  		argc--;
***************
*** 89,94 ****
--- 92,99 ----
  		argv++;
  		nflag++;
  	}
+ 	setbuffer(stderr, stderrbuf, sizeof (stderrbuf));
+ 
  	if (argc>1) {
  		if (freopen(argv[1], "r", stdin) == NULL) {
  			fprintf(stderr, "C2: can't find %s\n", argv[1]);
*** /usr/src/lib/cpp/cpp.c.old	Tue Aug 13 07:31:47 1991
--- /usr/src/lib/cpp/cpp.c	Wed Jun 12 11:03:34 1996
***************
*** 1,4 ****
! /* static char sccsid[] = "@(#)cpp.c	1.8 5/16/84"; */
  
  #ifdef FLEXNAMES
  #define	NCPS	128
--- 1,4 ----
! /* static char sccsid[] = "@(#)cpp.c	1.8.1 1996/6/12"; */
  
  #ifdef FLEXNAMES
  #define	NCPS	128
***************
*** 165,171 ****
  #define CONT  2
  #define BACK  3
  STATIC	int	ifno;
! # define NPREDEF 20
  STATIC	char *prespc[NPREDEF];
  STATIC	char **predef = prespc;
  STATIC	char *punspc[NPREDEF];
--- 165,171 ----
  #define CONT  2
  #define BACK  3
  STATIC	int	ifno;
! # define NPREDEF 30
  STATIC	char *prespc[NPREDEF];
  STATIC	char **predef = prespc;
  STATIC	char *punspc[NPREDEF];
*** /VERSION.old	Fri Jun  7 22:01:39 1996
--- /VERSION	Wed Jun 12 11:01:10 1996
***************
*** 1,4 ****
! Current Patch Level: 323
  
  2.11 BSD
  ============
--- 1,4 ----
! Current Patch Level: 324
  
  2.11 BSD
  ============