History log of /freebsd-10.0-release/lib/libc/stdio/vfwprintf.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 259065 07-Dec-2013 gjb

- Copy stable/10 (r259064) to releng/10.0 as part of the
10.0-RELEASE cycle.
- Update __FreeBSD_version [1]
- Set branch name to -RC1

[1] 10.0-CURRENT __FreeBSD_version value ended at '55', so
start releng/10.0 at '100' so the branch is started with
a value ending in zero.

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

# 256281 10-Oct-2013 gjb

Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.

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


# 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.