Subject: bin/149: ranlib(1) trashes archives when given more than one
To: None <gnats-admin>
From: None <thomas@mathematik.uni-Bremen.de>
List: netbsd-bugs
Date: 03/02/1994 18:35:01
>Number:         149
>Category:       bin
>Synopsis:       ranlib(1) trashes archives when given more than one
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gnats-admin (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar  2 18:35:01 1994
>Originator:     Thomas Eberhardt
>Organization:
CeVis, University of Bremen, Germany
>Release:        
>Environment:
	
System: NetBSD ed209 0.9a ED209#0 i386

Machine: i386
>Description:
	ranlib goes crazy after processing the first library because it
	doesn't reset some vital variables.  It also consumes more and more
	memory since it also doesn't release the symbol table it built up.
	And the temporary file names it generates when the TMPDIR environment
	variable is set are bogus after the first archive. Also, it doesn't
	close the archives when using "-t".
>How-To-Repeat:
	ranlib liba.a libb.a

	libb.a is trashed.
>Fix:
*** build.c-	Fri Dec 17 08:16:34 1993
--- build.c	Thu Mar  3 03:12:44 1994
***************
*** 63,68 ****
--- 63,71 ----
  } RLIB;
  RLIB *rhead, **pnext;
  
+ long symcnt;				/* symbol count */
+ long tsymlen;				/* total string length */
+ 
  FILE *fp;
  static void rexec(), symobj();
  
***************
*** 79,84 ****
--- 82,88 ----
  	SETCF(afd, archive, tfd, tname, RPAD|WPAD);
  
  	/* Read through the archive, creating list of symbols. */
+ 	symcnt = tsymlen = 0;
  	pnext = &rhead;
  	while(get_arobj(afd)) {
  		if (!strcmp(chdr.name, RANLIBMAG)) {
***************
*** 107,115 ****
  	return(0);
  }
  
- long symcnt;				/* symbol count */
- long tsymlen;				/* total string length */
- 
  /*
   * rexec
   *	Read the exec structure; ignore any files that don't look
--- 111,116 ----
***************
*** 216,222 ****
  static void
  symobj()
  {
! 	register RLIB *rp;
  	struct ranlib rn;
  	char hb[sizeof(struct ar_hdr) + 1], pad;
  	long ransize, size, stroff;
--- 217,223 ----
  static void
  symobj()
  {
! 	register RLIB *rp, *rnext;
  	struct ranlib rn;
  	char hb[sizeof(struct ar_hdr) + 1], pad;
  	long ransize, size, stroff;
***************
*** 269,277 ****
  		error(tname);
  
  	/* Write out the string table. */
! 	for (rp = rhead; rp; rp = rp->next)
  		if (!fwrite(rp->sym, rp->symlen, 1, fp))
  			error(tname);
  
  	if (pad && !fwrite(&pad, sizeof(pad), 1, fp))
  		error(tname);
--- 270,282 ----
  		error(tname);
  
  	/* Write out the string table. */
! 	for (rp = rhead; rp; rp = rnext) {
  		if (!fwrite(rp->sym, rp->symlen, 1, fp))
  			error(tname);
+ 		rnext = rp->next;
+ 		free(rp);
+ 	}
+ 	rhead = NULL;
  
  	if (pad && !fwrite(&pad, sizeof(pad), 1, fp))
  		error(tname);
*** misc.c-	Tue Jan  4 12:37:02 1994
--- misc.c	Thu Mar  3 02:50:24 1994
***************
*** 53,59 ****
  
  tmp()
  {
! 	char *envtmp;
  	sigset_t set, oset;
  	static int first;
  	int fd;
--- 53,59 ----
  
  tmp()
  {
! 	static char *envtmp = NULL;
  	sigset_t set, oset;
  	static int first;
  	int fd;
*** touch.c-	Fri Dec 17 08:16:38 1993
--- touch.c	Thu Mar  3 02:49:21 1994
***************
*** 66,71 ****
--- 66,72 ----
  		return(1);
  	}
  	settime(afd);
+ 	close_archive(afd);
  	return(0);
  }
  
>Audit-Trail:
>Unformatted:


------------------------------------------------------------------------------