Bug in USG 5.2 stdio package.

Phil Chadwick phil at qfdts.OZ
Wed Nov 7 08:36:48 AEST 1984


In our release of Sys V r2.0 there were four versions of 
"printf" containing a bug which directs the output into the bit
bucket under some circumstances.  The subroutines live in the
directory "/usr/src/lib/libc/port/print".  They are:

	fprintf.c	version 1.5	) Our release may well
	printf.c	version 1.5	\ differ from yours.
	vfprintf.c	version 1.1	/ Check that the versions
	vprintf.c	version 1.1	) are the same!

These routines all fail under circumstances where:

	(a)  a stream is opened for update,
	(b)  data are read from or written to the stream,
	(c)  an fseek() is issued,
	(d)  one of the above *printf() routines is used to
	     write a small amount of data to the stream
	     (i.e. less than a buffer full),
	(e)  the stream is fflush()'d.

The cause of the problem appears to be due to a failure of the
printf routines to reset the _cnt field of the appropriate FILE
structure from zero to the size of the buffer being used prior
to writing to the stream.

I applied the following fixes to fprintf.c, printf.c, vfprintf.c
and vprintf.c some time ago and have had no further problems:

	(a) Insert "#include ../stdio/stdiom.h" in each file.

	(b) For fprintf.c and vfprintf.c replace the first 
	    compound if statement with:

		if(_WRTCHK(iop) != 0)
			return EOF;

	(c) For printf.c and vprintf.c replace the first 
	    compound if statement with:

		if(_WRTCHK(stdout) != 0)
			return EOF;

----
Phil Chadwick			Australia:	(07) 2296500
Department of Forestry		International:	+61 7 2296500
PO Box 5
Brisbane, Roma Street		SUN:	phil:qfdts		
AUSTRALIA	4001		UUCP:	{decvax,vax135}!mulga!phil:qfdts



More information about the Net.bugs.usg mailing list