[4212] in Athena Bugs
rt 6.4R: sprintf, _doprnt
daemon@ATHENA.MIT.EDU (Jonathan I. Kamens)
Tue Feb 13 13:49:03 1990
Date: Tue, 13 Feb 90 13:48:45 -0500
From: Jonathan I. Kamens <jik@PIT-MANAGER.MIT.EDU>
To: bugs@ATHENA.MIT.EDU
System name: pit-manager
Type and version: RTPC-ROMPC 6.4R
Display type: apa16
megapel
What were you trying to do?
Use the return value of sprintf(), which is supposed to be
(according to <stdio.h>) an int, presumably representing the
length of the string generated by sprintf.
What's wrong:
The sources for sprintf() on the RT
(/source/bsd-4.3/common/lib/libc/stdio/sprintf.c) return the
return value of _doprnt(), assuming that _doprnt() has returned
the length of the string it has generated. This is, in fact,
false -- _doprnt() doesn't return anything, which means that
sprintf() returns garbage.
What should have happened:
_doprnt() should return the length of the string it has
generated. I believe that this only requires adding one line
of source code to
/source/bsd-4.3/rt/lib/libc/rt/stdio/doprnt.c -- "return(p -
t);" as the last line of the procedure. I'm not 100% certain
of this, though.
Please describe any relevant documentation references:
sprintf(3S), /source/bsd-4.3/rt/lib/libc/rt/stdio/doprnt.c,
/source/bsd-4.3/common/lib/libc/stdio/sprintf.c,
/usr/include/stdio.h.
jik
P.S. When stdio.h was modified for the 6.4R release so that sprintf()
would be declared as returning an int, it should have been
*checked* on all platforms before assuming that the right thing
would happen. The fact that it wasn't is irritating.