Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!rutgers!clyde!watmath!watnot!watcgl!onfcanim!dave
From: dave@onfcanim.UUCP (Dave Martindale)
Newsgroups: news.software.b
Subject: sortactive() stomps memory unless SORTACTIVE defined
Message-ID: <15160@onfcanim.UUCP>
Date: Thu, 18-Dec-86 22:02:11 EST
Article-I.D.: onfcanim.15160
Posted: Thu Dec 18 22:02:11 1986
Date-Received: Fri, 19-Dec-86 07:20:08 EST
Organization: National Film Board / Office national du film, Montreal
Lines: 46

The function sortactive() in rfuncs.c reads stuff into a structure
pointed to by "tp".  Unfortunately, the code that initializes "tp"
is compiled in only if SORTACTIVE is defined.  Without it, some
random memory is stomped.  In my case, it was the end of argv and the
beginning of the environment.  There is no visible effect of the error
until you execute a command (like 'c') that forks to do its work,
at which point someone complains about the format of the environment.

The fix is trivial - move the initialization outside the conditional code:

*** /tmp/oldrfuncs.c	Mon Nov 10 23:20:41 1986
--- ./rfuncs.c	Thu Dec 18 21:52:35 1986
***************
*** 618,624
  	p = ACTIVE;
  	ACTIVE = newactivename;
  	afp = xfopen(p, "r");
- 	tp = table;
  #else /* !SORTACTIVE */
  	afp = xfopen(ACTIVE, "r");
  #endif /* !SORTACTIVE */

--- 618,623 -----
  	p = ACTIVE;
  	ACTIVE = newactivename;
  	afp = xfopen(p, "r");
  #else /* !SORTACTIVE */
  	afp = xfopen(ACTIVE, "r");
  #endif /* !SORTACTIVE */
***************
*** 622,627
  #else /* !SORTACTIVE */
  	afp = xfopen(ACTIVE, "r");
  #endif /* !SORTACTIVE */
  	while (fgets(aline, sizeof aline, afp) != NULL) {
  		if (sscanf(aline,"%s %ld %ld %c", ngname, &tp->maxart,
  		    &tp->minart, &tp->yn) != 4) 

--- 621,627 -----
  #else /* !SORTACTIVE */
  	afp = xfopen(ACTIVE, "r");
  #endif /* !SORTACTIVE */
+ 	tp = table;
  	while (fgets(aline, sizeof aline, afp) != NULL) {
  		if (sscanf(aline,"%s %ld %ld %c", ngname, &tp->maxart,
  		    &tp->minart, &tp->yn) != 4)