Subject: bin/527: Bug in /usr/src/usr.bin/ar/contents.c on Big-Endian architectures
To: None <gnats-admin@sun-lamp.cs.berkeley.edu>
From: None <earle@netbsd4me.jpl.nasa.gov>
List: netbsd-bugs
Date: 10/18/1994 20:05:04
>Number:         527
>Category:       bin
>Synopsis:       Object modules in archive libraries listed as being of size 0
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gnats-admin (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Oct 18 20:05:02 1994
>Originator:     Greg Earle
>Organization:
JPL
>Release:        1.0_BETA
>Environment:
	
System: NetBSD netbsd4me.jpl.nasa.gov 1.0_BETA NetBSD 1.0_BETA (NETBSD4ME) #2: Wed Sep 7 02:56:17 PDT 1994 earle@netbsd4me.jpl.nasa.gov:/usr/src/sys/arch/sparc/compile/NETBSD4ME sparc


>Description:
	Running "ar -tv lib[mumble].a" on a Big-Endian architecture machine
	yields file sizes for the .o modules that are all "0" length.

	This is because the "size" field in the archive library was changed to
	be "off_t" sometime back, but the routine that prints out the sizes
	of archive members wasn't changed to reflect this.  It still uses a
	"%8ld" to print the member size, instead of using the "q" quad
	qualifier to the "d" in the printf() call.  (Aside: the "q" modifier
	is not mentioned in the printf(3) man page, either.)  I also suggest
	that using "%8" in a printf() for an off_t value is also a mistake,
	since the off_t implies that the file size could be larger than will
	fit in the %8ld format statement.

	The bug does not show up on Little-Endian machines because the "%8ld"
	argument shows the lower half of the off_t value, given the byte order.
	For values less than those which would overspill, the correct size is
	still printed on Little-Endian machines.

>How-To-Repeat:
	Run "ar -tv /usr/lib/libc.a" on a Big-Endian architecture machine
	(such as a SPARC) and watch the fun:

	netbsd4me# ar -tv /usr/lib/libc.a | head
	rw-r--r--       0/0             0 Aug  1 12:33 1994 __.SYMDEF
	rwxr-xr-x       0/10            0 Jul 29 01:17 1994 truncate.o
	rwxr-xr-x       0/10            0 Jul 29 01:17 1994 syscall.o
	rwxr-xr-x       0/10            0 Jul 29 01:17 1994 sigreturn.o
	rwxr-xr-x       0/10            0 Jul 29 01:17 1994 sigpending.o
	rwxr-xr-x       0/10            0 Jul 29 01:17 1994 setlogin.o
	rwxr-xr-x       0/10            0 Jul 29 01:17 1994 reboot.o
	rwxr-xr-x       0/10            0 Jul 29 01:17 1994 ptrace.o
	rwxr-xr-x       0/10            0 Jul 29 01:16 1994 exect.o
	rwxr-xr-x       0/10            0 Jul 29 01:16 1994 swab.o
	netbsd4me# 

	With the suggested fix (see below) in place, the results are:

netbsd4me# ./ar -tv /usr/lib/libc.a | head
rw-r--r--       0/0                 18250 Aug  1 12:33 1994 __.SYMDEF
rwxr-xr-x       0/10                  209 Jul 29 01:17 1994 truncate.o
rwxr-xr-x       0/10                  164 Jul 29 01:17 1994 syscall.o
rwxr-xr-x       0/10                  166 Jul 29 01:17 1994 sigreturn.o
rwxr-xr-x       0/10                  191 Jul 29 01:17 1994 sigpending.o
rwxr-xr-x       0/10                  242 Jul 29 01:17 1994 setlogin.o
rwxr-xr-x       0/10                  171 Jul 29 01:17 1994 reboot.o
rwxr-xr-x       0/10                  230 Jul 29 01:17 1994 ptrace.o
rwxr-xr-x       0/10                  162 Jul 29 01:16 1994 exect.o
rwxr-xr-x       0/10                  474 Jul 29 01:16 1994 swab.o
netbsd4me# 

>Fix:
	Suggest this change to /usr/src/usr.bin/ar/contents.c:

*** contents.c.orig	Thu Dec 16 23:04:39 1993
--- contents.c	Tue Oct 18 19:52:15 1994
***************
*** 78,80 ****
  			(void)strmode(chdr.mode, buf);
! 			(void)printf("%s %6d/%-6d %8ld ",
  			    buf + 1, chdr.uid, chdr.gid, chdr.size);
--- 78,80 ----
  			(void)strmode(chdr.mode, buf);
! 			(void)printf("%s %6d/%-6d %16qd ",
  			    buf + 1, chdr.uid, chdr.gid, chdr.size);
>Audit-Trail:
>Unformatted: