Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site wateng.UUCP
Path: utzoo!watmath!wateng!padpowell
From: padpowell@wateng.UUCP (PAD Powell)
Newsgroups: net.unix-wizards
Subject: Re: Does anybody have a version of SPRINTF with bounds checking and flame
Message-ID: <1336@wateng.UUCP>
Date: Wed, 22-Aug-84 10:38:44 EDT
Article-I.D.: wateng.1336
Posted: Wed Aug 22 10:38:44 1984
Date-Received: Thu, 23-Aug-84 00:35:43 EDT
References: <1323@wateng.UUCP>, <8132@umcp-cs.UUCP>
Organization: U of Waterloo, Ontario
Lines: 52

INTRODUCTION
Having been burned several times by the behaviour of sprintf,
I have just finished testing a new version, called snprintf,
and sxprintf, which have the exact functionality of sprintf,
but do bound checking.

In doing this, I discovered a couple of minor coding glitches in the
_doprnt() routine.  It was written in assembler, and the authors
have my sympathy.   I have the funniest feeling that many of the
sections of the conversion routines were DEC VMS sources.
It uses some of the very baroque VAX instructions...

I was going to post the changes to doprnt(), but discovered that the
diffs were longer than the source. I wonder if there is any problems
in posting the entire source to doprnt.s?

	Patrick Powell,
	U. Waterloo, VLSI Design Group,
	Waterloo Ont.

SUMMARY

snprintf( count, str, format, args )
	int count; char *str, *format, ...;
Exact functionality of sprintf, but will only generate count characters,
including trailing 0.  If it fails, it returns a NULL, otherwise it
returns s.

sxprintf( count, str, format, args )
	int count; char *str, *format, ...;
This has the exact functionality of snprintf, in that it does bound checking.
It does not append a trailing 0, and allows very nice reformatting of
fixed field items.

INSTALLATION
1. copy the snprintf.c,sxprintf.c,sprintf.c to /usr/src/lib/libc/stdio
	NOTE: save the old versions, you might want them.
2. copy doprnt.s to /usr/src/lib/libc/vax/stdio
3. update the lint library, by copying the llib-lc to
	/usr/src/usr.lib/lint/llib-lc, and then making the new lint libs
5. compile the lc library (moan).
	Actually, you can shorten this by using the make file,
	which has a quick "update" entry.  This does an "ar u *.o"
	on the object files and the /usr/lib/llibc

What are the benefits?
1. A bombproof version of the stdio library routines that does bounds
	checking.
2. A COMMENTED version of _doprnt.c, which also has some added error checking.


Patrick ("I hate sprintf") Powell