about summary refs log tree commit diff
path: root/src/stdio/vfwprintf.c
Commit message (Collapse)AuthorAgeFilesLines
* fix %lf in wprintfBrion Vibber2019-09-131-0/+2
| | | | | | | commit cc3a4466605fe8dfc31f3b75779110ac93055bc1 fixed this for printf but neglected to fix wprintf. Previously, %lf caused a failure to output.
* reduce spurious inclusion of libc.hRich Felker2018-09-121-0/+1
| | | | | | | | | | | | | | | | | | | | | libc.h was intended to be a header for access to global libc state and related interfaces, but ended up included all over the place because it was the way to get the weak_alias macro. most of the inclusions removed here are places where weak_alias was needed. a few were recently introduced for hidden. some go all the way back to when libc.h defined CANCELPT_BEGIN and _END, and all (wrongly implemented) cancellation points had to include it. remaining spurious users are mostly callers of the LOCK/UNLOCK macros and files that use the LFS64 macro to define the awful *64 aliases. in a few places, new inclusion of libc.h is added because several internal headers no longer implicitly include libc.h. declarations for __lockfile and __unlockfile are moved from libc.h to stdio_impl.h so that the latter does not need libc.h. putting them in libc.h made no sense at all, since the macros in stdio_impl.h are needed to use them correctly anyway.
* vfwprintf: honor field width with 'c' format typeA. Wilcox2018-08-281-1/+4
|
* remove ineffective compiler assist from printfAlexander Monakov2017-07-041-2/+0
| | | | | | The switch statement has no 'default:' case and the function ends immediately following the switch, so the extra comparison did not communicate any extra information to the compiler.
* reapply va_arg hacks removal to wprintfAlexander Monakov2017-07-041-26/+1
| | | | | commit 58e2396a9aa23c132faf4198ca4d779c84955b38 missed that the same code was duplicated in implementation of vfwprintf.
* fix integer overflows and uncaught EOVERFLOW in printf coreRich Felker2016-10-201-24/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* fix padding string formats to width in wide printf variantsRich Felker2016-03-161-4/+4
| | | | | | | 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.
* fix idiom for setting stdio stream orientation to wideRich Felker2015-06-131-1/+1
| | | | | | | | | | | | 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.
* add printing of null %s arguments as "(null)" in wide printfRich Felker2015-06-131-0/+1
| | | | | this is undefined, but supported in our implementation of the normal printf, so for consistency the wide variant should support it too.
* add %m support to wide printfRich Felker2015-06-131-0/+2
|
* correctly handle write errors encountered by printf-family functionsRich Felker2014-12-171-1/+6
| | | | | | | | | | | | | | | | | | 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.
* fix failure of wide printf/scanf functions to set wide orientationRich Felker2014-07-021-0/+1
| | | | | | 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.
* minor vfprintf and vfwprintf changes to please static code analyzersSzabolcs Nagy2013-10-071-4/+6
| | | | add missing va_end and remove some unnecessary code.
* removed unused variable in vfwprintfRich Felker2013-10-041-2/+1
|
* clean up stdio_impl.hRich Felker2012-11-081-0/+7
| | | | | | | | | | | 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.
* use restrict everywhere it's required by c99 and/or posix 2008Rich Felker2012-09-061-1/+1
| | | | | | | | 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.
* fix uninitialized var in vfwprintf printing 0-prec stringRich Felker2012-05-041-1/+1
| | | | this could lead to spurious failures of wide printf functions
* implement wprintf family of functionsRich Felker2011-03-171-0/+354
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.