History log of /seL4-test-master/projects/musllibc/src/stdio/vfwprintf.c
Revision Date Author Comments
# 167dfe96 19-Oct-2016 Rich Felker <dalias@aerifal.cx>

fix integer overflows and uncaught EOVERFLOW in printf core

this patch fixes a large number of missed internal signed-overflow
checks and errors in determining when the return value (output length)
would exceed INT_MAX, which should result in EOVERFLOW. some of the
issues fixed were reported by Alexander Cherepanov; others were found
in subsequent review of the code.

aside from the signed overflows being undefined behavior, the
following specific bugs were found to exist in practice:

- overflows computing length of floating point formats with huge
explicit precisions, integer formats with prefix characters and huge
explicit precisions, or string arguments or format strings longer
than INT_MAX, resulted in wrong return value and wrong %n results.

- literal width and precision values outside the range of int were
misinterpreted, yielding wrong behavior in at least one well-defined
case: string formats with precision greater than INT_MAX were
sometimes truncated.

- in cases where EOVERFLOW is produced, incorrect values could be
written for %n specifiers past the point of exceeding INT_MAX.

in addition to fixing these bugs, we now stop producing output
immediately when output length would exceed INT_MAX, rather than
continuing and returning an error only at the end.


# 4aac019a 16-Mar-2016 Rich Felker <dalias@aerifal.cx>

fix padding string formats to width in wide printf variants

the idiom fprintf(f, "%.*s", n, "") was wrongly used in vfwprintf as a
means of producing n spaces; instead it produces no output. the
correct form is fprintf(f, "%*s", n, ""), using width instead of
precision, since for %s the later is a maximum rather than a minimum.


# 536c6d5a 12-Jun-2015 Rich Felker <dalias@aerifal.cx>

fix idiom for setting stdio stream orientation to wide

the old idiom, f->mode |= f->mode+1, was adapted from the idiom for
setting byte orientation, f->mode |= f->mode-1, but the adaptation was
incorrect. unless the stream was alreasdy set byte-oriented, this code
incremented f->mode each time it was executed, which would eventually
lead to overflow. it could be fixed by changing it to f->mode |= 1,
but upcoming changes will require slightly more work at the time of
wide orientation, so it makes sense to just call fwide. as an
optimization in the single-character functions, fwide is only called
if the stream is not already wide-oriented.


# f8f565df 12-Jun-2015 Rich Felker <dalias@aerifal.cx>

add printing of null %s arguments as "(null)" in wide printf

this is undefined, but supported in our implementation of the normal
printf, so for consistency the wide variant should support it too.


# f9e25d81 12-Jun-2015 Rich Felker <dalias@aerifal.cx>

add %m support to wide printf


# d42269d7 17-Dec-2014 Rich Felker <dalias@aerifal.cx>

correctly handle write errors encountered by printf-family functions

previously, write errors neither stopped further output attempts nor
caused the function to return an error to the caller. this could
result in silent loss of output, possibly in the middle of output in
the event of a non-permanent error.

the simplest solution is temporarily clearing the error flag for the
target stream, then suppressing further output when the error flag is
set and checking/restoring it at the end of the operation to determine
the correct return value.

since the wide version of the code internally calls the narrow fprintf
to perform some of its underlying operations, initial clearing of the
error flag is suppressed when performing a narrow vfprintf on a
wide-oriented stream. this is not a problem since the behavior of
narrow operations on wide-oriented streams is undefined.


# 984c25b7 01-Jul-2014 Rich Felker <dalias@aerifal.cx>

fix failure of wide printf/scanf functions to set wide orientation

in some cases, these functions internally call a byte-based input or
output function before calling getwc/putwc, so they cannot rely on the
latter to set the orientation.


# 49b3a0d2 07-Oct-2013 Szabolcs Nagy <nsz@port70.net>

minor vfprintf and vfwprintf changes to please static code analyzers

add missing va_end and remove some unnecessary code.


# a938b5a1 03-Oct-2013 Rich Felker <dalias@aerifal.cx>

removed unused variable in vfwprintf


# 835f9f95 08-Nov-2012 Rich Felker <dalias@aerifal.cx>

clean up stdio_impl.h

this header evolved to facilitate the extremely lazy practice of
omitting explicit includes of the necessary headers in individual
stdio source files; not only was this sloppy, but it also increased
build time.

now, stdio_impl.h is only including the headers it needs for its own
use; any further headers needed by source files are included directly
where needed.


# 400c5e5c 06-Sep-2012 Rich Felker <dalias@aerifal.cx>

use restrict everywhere it's required by c99 and/or posix 2008

to deal with the fact that the public headers may be used with pre-c99
compilers, __restrict is used in place of restrict, and defined
appropriately for any supported compiler. we also avoid the form
[restrict] since older versions of gcc rejected it due to a bug in the
original c99 standard, and instead use the form *restrict.


# db4096c5 03-May-2012 Rich Felker <dalias@aerifal.cx>

fix uninitialized var in vfwprintf printing 0-prec string

this could lead to spurious failures of wide printf functions


# c35bb664 17-Mar-2011 Rich Felker <dalias@aerifal.cx>

implement wprintf family of functions

this implementation is extremely ugly and inefficient, but it avoids a
good deal of code duplication and bloat. it may be cleaned up later to
eliminate the remaining code duplication and some of the warts, but i
don't really care about its performance.

note that swprintf is not yet implemented.