History log of /freebsd-11-stable/lib/libc/stdio/vfwprintf.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 331722 29-Mar-2018 eadler

Revert r330897:

This was intended to be a non-functional change. It wasn't. The commit
message was thus wrong. In addition it broke arm, and merged crypto
related code.

Revert with prejudice.

This revert skips files touched in r316370 since that commit was since
MFCed. This revert also skips files that require $FreeBSD$ property
changes.

Thank you to those who helped me get out of this mess including but not
limited to gonzo, kevans, rgrimes.

Requested by: gjb (re)


# 330897 14-Mar-2018 eadler

Partial merge of the SPDX changes

These changes are incomplete but are making it difficult
to determine what other changes can/should be merged.

No objections from: pfg


# 320942 13-Jul-2017 kib

MFC r320472,r320508,r320509:
Make stdio deferred cancel-safe.


# 304890 27-Aug-2016 ache

MFC r304810

Don't check for __SERR which may stick from one of any previous stdio
functions.
__SERR is for user and the rest of stdio code do not check it
for error sensing internally, only set it.
In vf(w)printf.c here it is more easy to save __SERR, clear and restore it.


# 302408 07-Jul-2016 gjb

Copy head@r302406 to stable/11 as part of the 11.0-RELEASE cycle.
Prune svn:mergeinfo from the new branch, as nothing has been merged
here.

Additional commits post-branch will follow.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation


/freebsd-11-stable/MAINTAINERS
/freebsd-11-stable/cddl
/freebsd-11-stable/cddl/contrib/opensolaris
/freebsd-11-stable/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/print
/freebsd-11-stable/cddl/contrib/opensolaris/cmd/zfs
/freebsd-11-stable/cddl/contrib/opensolaris/lib/libzfs
/freebsd-11-stable/contrib/amd
/freebsd-11-stable/contrib/apr
/freebsd-11-stable/contrib/apr-util
/freebsd-11-stable/contrib/atf
/freebsd-11-stable/contrib/binutils
/freebsd-11-stable/contrib/bmake
/freebsd-11-stable/contrib/byacc
/freebsd-11-stable/contrib/bzip2
/freebsd-11-stable/contrib/com_err
/freebsd-11-stable/contrib/compiler-rt
/freebsd-11-stable/contrib/dialog
/freebsd-11-stable/contrib/dma
/freebsd-11-stable/contrib/dtc
/freebsd-11-stable/contrib/ee
/freebsd-11-stable/contrib/elftoolchain
/freebsd-11-stable/contrib/elftoolchain/ar
/freebsd-11-stable/contrib/elftoolchain/brandelf
/freebsd-11-stable/contrib/elftoolchain/elfdump
/freebsd-11-stable/contrib/expat
/freebsd-11-stable/contrib/file
/freebsd-11-stable/contrib/gcc
/freebsd-11-stable/contrib/gcclibs/libgomp
/freebsd-11-stable/contrib/gdb
/freebsd-11-stable/contrib/gdtoa
/freebsd-11-stable/contrib/groff
/freebsd-11-stable/contrib/ipfilter
/freebsd-11-stable/contrib/ldns
/freebsd-11-stable/contrib/ldns-host
/freebsd-11-stable/contrib/less
/freebsd-11-stable/contrib/libarchive
/freebsd-11-stable/contrib/libarchive/cpio
/freebsd-11-stable/contrib/libarchive/libarchive
/freebsd-11-stable/contrib/libarchive/libarchive_fe
/freebsd-11-stable/contrib/libarchive/tar
/freebsd-11-stable/contrib/libc++
/freebsd-11-stable/contrib/libc-vis
/freebsd-11-stable/contrib/libcxxrt
/freebsd-11-stable/contrib/libexecinfo
/freebsd-11-stable/contrib/libpcap
/freebsd-11-stable/contrib/libstdc++
/freebsd-11-stable/contrib/libucl
/freebsd-11-stable/contrib/libxo
/freebsd-11-stable/contrib/llvm
/freebsd-11-stable/contrib/llvm/projects/libunwind
/freebsd-11-stable/contrib/llvm/tools/clang
/freebsd-11-stable/contrib/llvm/tools/lldb
/freebsd-11-stable/contrib/llvm/tools/llvm-dwarfdump
/freebsd-11-stable/contrib/llvm/tools/llvm-lto
/freebsd-11-stable/contrib/mdocml
/freebsd-11-stable/contrib/mtree
/freebsd-11-stable/contrib/ncurses
/freebsd-11-stable/contrib/netcat
/freebsd-11-stable/contrib/ntp
/freebsd-11-stable/contrib/nvi
/freebsd-11-stable/contrib/one-true-awk
/freebsd-11-stable/contrib/openbsm
/freebsd-11-stable/contrib/openpam
/freebsd-11-stable/contrib/openresolv
/freebsd-11-stable/contrib/pf
/freebsd-11-stable/contrib/sendmail
/freebsd-11-stable/contrib/serf
/freebsd-11-stable/contrib/sqlite3
/freebsd-11-stable/contrib/subversion
/freebsd-11-stable/contrib/tcpdump
/freebsd-11-stable/contrib/tcsh
/freebsd-11-stable/contrib/tnftp
/freebsd-11-stable/contrib/top
/freebsd-11-stable/contrib/top/install-sh
/freebsd-11-stable/contrib/tzcode/stdtime
/freebsd-11-stable/contrib/tzcode/zic
/freebsd-11-stable/contrib/tzdata
/freebsd-11-stable/contrib/unbound
/freebsd-11-stable/contrib/vis
/freebsd-11-stable/contrib/wpa
/freebsd-11-stable/contrib/xz
/freebsd-11-stable/crypto/heimdal
/freebsd-11-stable/crypto/openssh
/freebsd-11-stable/crypto/openssl
/freebsd-11-stable/gnu/lib
/freebsd-11-stable/gnu/usr.bin/binutils
/freebsd-11-stable/gnu/usr.bin/cc/cc_tools
/freebsd-11-stable/gnu/usr.bin/gdb
/freebsd-11-stable/lib/libc/locale/ascii.c
/freebsd-11-stable/sys/cddl/contrib/opensolaris
/freebsd-11-stable/sys/contrib/dev/acpica
/freebsd-11-stable/sys/contrib/ipfilter
/freebsd-11-stable/sys/contrib/libfdt
/freebsd-11-stable/sys/contrib/octeon-sdk
/freebsd-11-stable/sys/contrib/x86emu
/freebsd-11-stable/sys/contrib/xz-embedded
/freebsd-11-stable/usr.sbin/bhyve/atkbdc.h
/freebsd-11-stable/usr.sbin/bhyve/bhyvegc.c
/freebsd-11-stable/usr.sbin/bhyve/bhyvegc.h
/freebsd-11-stable/usr.sbin/bhyve/console.c
/freebsd-11-stable/usr.sbin/bhyve/console.h
/freebsd-11-stable/usr.sbin/bhyve/pci_fbuf.c
/freebsd-11-stable/usr.sbin/bhyve/pci_xhci.c
/freebsd-11-stable/usr.sbin/bhyve/pci_xhci.h
/freebsd-11-stable/usr.sbin/bhyve/ps2kbd.c
/freebsd-11-stable/usr.sbin/bhyve/ps2kbd.h
/freebsd-11-stable/usr.sbin/bhyve/ps2mouse.c
/freebsd-11-stable/usr.sbin/bhyve/ps2mouse.h
/freebsd-11-stable/usr.sbin/bhyve/rfb.c
/freebsd-11-stable/usr.sbin/bhyve/rfb.h
/freebsd-11-stable/usr.sbin/bhyve/sockstream.c
/freebsd-11-stable/usr.sbin/bhyve/sockstream.h
/freebsd-11-stable/usr.sbin/bhyve/usb_emul.c
/freebsd-11-stable/usr.sbin/bhyve/usb_emul.h
/freebsd-11-stable/usr.sbin/bhyve/usb_mouse.c
/freebsd-11-stable/usr.sbin/bhyve/vga.c
/freebsd-11-stable/usr.sbin/bhyve/vga.h
# 268930 20-Jul-2014 pfg

Adjust errno on failed prepwrite.

Obtained from: Apple Inc. (Libc 997.90.3)
Phabric: D442
MFC after: 1 week


# 249808 23-Apr-2013 emaste

Renumber clauses to reduce diffs to other versions

NetBSD, OpenBSD, and Android's Bionic all number the clauses 1 through 3,
so follow suit to make comparison easier.

Acked-by: imp@


# 234531 21-Apr-2012 das

If the size passed to {,v}s{w,n}printf is larger than INT_MAX+1
(i.e., the return value would overflow), set errno to EOVERFLOW
and return an error. This improves the chances that buggy
applications -- for instance, ones that pass in a negative integer
as the size due to a bogus calculation -- will fail in safe ways.
Returning an error in these situations is specified by POSIX, but
POSIX appears to have an off-by-one error that isn't duplicated in
this change.

Previously, some of these functions would silently cap the size at
INT_MAX+1, and others would exit with an error after writing more
than INT_MAX characters.

PR: 39256
MFC after: 2 weeks


# 227753 20-Nov-2011 theraven

Implement xlocale APIs from Darwin, mainly for use by libc++. This adds a
load of _l suffixed versions of various standard library functions that use
the global locale, making them take an explicit locale parameter. Also
adds support for per-thread locales. This work was funded by the FreeBSD
Foundation.

Please test any code you have that uses the C standard locale functions!

Reviewed by: das (gdtoa changes)
Approved by: dim (mentor)


# 199782 25-Nov-2009 wollman

In __mbsconv(), if prec was zero, nconv could have been used
uninitialized. Initialize it to a safe value so that there's no
chance of returning an error if stack garbage happens to be equal to
(size_t)-1 or (size_t)-2.

Found by: Clang static analyzer
MFC after: 7 days


# 189138 28-Feb-2009 das

Replace a dozen lines of code with a call to strnlen() / wcsnlen().


# 189131 28-Feb-2009 das

Make sure %zd treats negative arguments properly on 32-bit platforms.
Fix harmless but related bugs in %_$zd and %_$tu.

PR: 131880
MFC after: 1 week


# 187582 22-Jan-2009 das

Add support for multibyte thousands_sep encodings, e.g., U+066C.
The integer thousands' separator code is rewritten in order to
avoid having to preallocate a buffer for the largest possible
digit string with the most possible instances of the longest
possible multibyte thousands' separator. The new version inserts
thousands' separators for integers using the same code as floating point.


# 187421 19-Jan-2009 das

Add support for multibyte decimal_point encodings, e.g., U+066B.


# 187369 17-Jan-2009 das

When f[w]printf() is called on an unbuffered file like stdout, it
sets up a fake buffered FILE and then effectively calls itself
recursively. Unfortunately, gcc doesn't know how to do tail call
elimination in this case, and actually makes things worse by
inlining __sbprintf(). This means that f[w]printf() to stderr was
allocating about 5k of stack on 64-bit platforms, much of which was
never used.

I've reorganized things to eliminate the waste. In addition to saving
some stack space, this improves performance in my tests by anywhere
from 5% to 17% (depending on the test) when -fstack-protector is
enabled. I found no statistically significant performance difference
when stack protection is turned off. (The tests redirected stderr to
/dev/null.)


# 187284 15-Jan-2009 das

Reduce code duplication by moving functions that are identical in both
vfprintf.c and vfwprintf.c (except for char/wchar_t differences) to a
common header file.


# 187277 15-Jan-2009 das

Convert the insidious macros that handle printf()'s buffering into
slightly less evil inline functions, and move the buffering state into
a struct. This will make it possible for helper routines to produce
output for printf() directly, making it possible to untangle the code
somewhat.

In wprintf(), use the same buffering mechanism to reduce diffs to
printf(). This has the side-effect of causing wprintf() to catch write
errors that it previously ignored.


# 185904 11-Dec-2008 das

Consolidate some variable initializations. No substantive change.


# 181281 04-Aug-2008 cperciva

Initialize "nconv" to a reasonable value in all code paths. Prior to
this commit, sprintf("%s", "") could fail depending on what happened
to be on the stack.

Found by: LLVM/Clang Static Checker


# 180106 29-Jun-2008 das

Correctly handle malloc() failure. While here, reduce the code size a
bit by removing some calls to the inline function addtype().


# 180104 29-Jun-2008 das

Reduce the level of duplication between vfprintf() and vfwprintf()
by moving the positional argument handling code to a new file,
printf-pos.c, and moving common definitions to printflocal.h.
No functional change intended.


# 180102 29-Jun-2008 das

Begin de-spaghettifying the code that handles positional arguments.
In particular, encapsulate the state of the type table in a struct,
and add inline functions to initialize, free, and manipulate that
state. This replaces some ugly macros that made proper error handling
impossible.

While here, remove an unneeded test for NULL and a variable that is
initialized (many times!) but never used. The compiler didn't catch
these because of rampant use of the same variable to mean different
things in different places.

This commit should not cause any changes in functionality.


# 178287 17-Apr-2008 jhb

Next stage of stdio cleanup: Retire __sFILEX and merge the fields back into
__sFILE. This was supposed to be done in 6.0. Some notes:
- Where possible I restored the various lines to their pre-__sFILEX state.
- Retire INITEXTRA() and just initialize the wchar bits (orientation and
mbstate) explicitly instead. The various places that used INITEXTRA
didn't need the locking fields or _up initialized. (Some places needed
_up to exist and not be off the end of a NULL or garbage pointer, but
they didn't require it to be initialized to a specific value.)
- For now, stdio.h "knows" that pthread_t is a 'struct pthread *' to
avoid namespace pollution of including all the pthread types in stdio.h.
Once we remove all the inlines and make __sFILE private it can go back
to using pthread_t, etc.
- This does not remove any of the inlines currently and does not change
any of the public ABI of 'FILE'.

MFC after: 1 month
Reviewed by: peter


# 174733 17-Dec-2007 das

Catch up with vfprintf.c,v 1.77.


# 165903 08-Jan-2007 imp

Per Regents of the University of Calfornia letter, remove advertising
clause.

# If I've done so improperly on a file, please let me know.


# 162523 21-Sep-2006 kan

Use correct type in va_arg argument.


# 157381 01-Apr-2006 phk

Add missing #if's for NO_FLOATING_POINT


# 145172 16-Apr-2005 das

Be bug-for-bug compatible with the C standard with respect to
printf("%#.0o", 0). Cite an amusing passage from a defect report.


# 134332 26-Aug-2004 des

Don't forget to va_end() the va_list we get from va_copy().

Submitted by: Sean McNeil <sean@mcneil.com>
MFC after: 3 days


# 130242 08-Jun-2004 stefanf

The third operand of the conditional operator should have type void too.

Approved by: das (mentor)


# 130231 08-Jun-2004 das

Rename cantwrite() to prepwrite(). The latter is less confusing,
since the macro isn't really a predicate, and it has side-effects.


# 128843 02-May-2004 obrien

Fix damaged FBSDID.


# 128821 02-May-2004 das

Merge vfprintf.c, v1.65:
- s/#ifdef FLOATING_POINT/#ifndef NO_FLOATING_POINT/
- Remove HEXFLOAT


# 128550 22-Apr-2004 tjr

Use the correct size to allocate, copy and clear argument type tables
after their change from an array of char to an array of enum.
This fixes problems that occurred when using positional arguments in
format strings, particularly with more than STATIC_ARG_TBL_SIZE (8)
of them.

PR: 65841
Submitted by: Steven Smith (mostly)


# 128002 07-Apr-2004 tjr

Prepare to handle trivial state-dependent encodings. Full support for
state-dependent encodings with locking shifts will come later if there
is demand for it.


# 124887 23-Jan-2004 das

Merge vfprintf.c, v1.61 and 1.62. For compatibility with __hdtoa()
and to reduce diffs between vfprintf.c and vfwprintf.c, declare xdigs*
to be char arrays rather than wchar_t arrays.

In collaboration with: tjr


# 124174 06-Jan-2004 nectar

Remove unused variables and function declarations. Add missing headers.


# 122547 12-Nov-2003 tjr

Use __sfvwrite() instead of __sputc() via __fputwc() to write to fake
string files (__SSTR flag set). This is necessary because __sputc()
does not respect the __SALC flag, and crashes trying to flush the buffer
instead of resizing it.

PR: 59167


# 122105 05-Nov-2003 tjr

Pass NULL instead of a pointer to a zeroed mbstate_t object.


# 113723 19-Apr-2003 das

%E-like %g and %G conversions should remove trailing zeroes unless
the # flag is present. Implement this behavior and add a comment
describing it.

Noticed by: Enache Adrian <enache@rdslink.ro>
Pointy hat to: das


# 113470 14-Apr-2003 tjr

Merge in vfprintf.c rev. 1.58.


# 113199 07-Apr-2003 tjr

Catch up with recent vfprintf.c changes.


# 113143 05-Apr-2003 das

Add missing #include to unbreak previous commit.


# 113142 05-Apr-2003 das

Correct some buffer sizes.

- __vfprintf()'s 'buf' has never been used for floating point, so
don't define it in terms of (incorrect) constants describing
floating point numbers. The actual size needed depends on
sizeof(uintmax_t) and locale details, so I slightly overestimated.

- We don't need a 308-character buffer to store the string "308".
With long doubles and %a we need more than three characters, though.


# 112229 14-Mar-2003 tjr

Merge vfprintf.c revision 1.52.


# 112223 14-Mar-2003 tjr

Unexpand RCS tag.


# 112174 13-Mar-2003 tjr

MFp4: Catch up to recent __dtoa() interface changes and removal of cvt()'s
last argument.


# 105234 16-Oct-2002 tjr

Set the error bit on the stream if an encoding error occurs. Improve
handling of multibyte sequences representing null wide characters.


# 105204 16-Oct-2002 tjr

Add support for the XSI %C and %S formats, which are the same as %lc
and %ls.


# 103876 23-Sep-2002 tjr

Use the new va_copy macro to copy variable argument lists instead of
assignment. This is needed on powerpc but is also more correct for the
other ports.

Submitted by: grehan
Tested on: alpha, i386, sparc64


# 103739 21-Sep-2002 tjr

Add implementations of the wprintf() family of functions, which perform
formatted wide-character output.