summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio
Commit message (Collapse)AuthorAgeFilesLines
...
* Bugfix: %n doesn't count as a conversion, sodas2012-04-222-2/+0
| | | | sscanf("abc", "ab%ncd", &i) returns EOF, not 0.
* Refactor scanf to improve modularity. Conversions are now performeddas2012-04-222-668/+843
| | | | | | by separate conversion functions. This will hopefully make bugs more noticeable (I noticed several already) and provide opportunities to reduce code duplication.
* As noted by Peter Jeremy, r234528 only partially fixed the infinitedas2012-04-211-1/+1
| | | | | | | loop bug introduced in r187302. This completes the fix. PR: 167039 MFC after: 3 days
* If the size passed to {,v}s{w,n}printf is larger than INT_MAX+1das2012-04-215-6/+29
| | | | | | | | | | | | | | | | | (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
* - Fix the claim that the output is always null-terminated. This isn'tdas2012-04-211-17/+29
| | | | | | | | | | | true if the size is zero. - Fix a claim that sprintf() is the same as snprintf() with an infinite size. It's equivalent to snprintf() with a size of INT_MAX + 1. - Document the return values in the return values section. - Document the possible errno value of EOVERFLOW. MFC after: 2 weeks
* Ensure that the {,v}swprintf functions always null-terminate thedas2012-04-211-0/+3
| | | | output string, even if an encoding error or malloc failure occurs.
* Fix a bug introduced in r187302 that was causing fputws() to enter andas2012-04-211-1/+1
| | | | | | | | | infinite loop pretty much unconditionally. It's remarkable that the patch that introduced the bug was never tested, but even more remarkable that nobody noticed for over two years. PR: 167039 MFC after: 3 days
* Remove trailing whitespace per mdoc lint warningeadler2012-03-291-1/+1
| | | | | | | Disussed with: gavin No objection from: doc Approved by: joel MFC after: 3 days
* Remove outdated comment of seven yearseadler2012-03-041-7/+0
| | | | | | PR: docs/116116 Approved by: cperciva MFC after: 1 week
* Remove reference to gcc's non-standard -fwritable-strings, whicheadler2012-03-041-7/+1
| | | | | | | | | doesn't exist in recent releases (and is bad advice anyway) PR: docs/163119 Submitted by: Yuri Pankov <yuri.pankov@gmail.com> Approved by: cperciva MFC after: 1 week
* Implement xlocale APIs from Darwin, mainly for use by libc++. This adds atheraven2011-11-2042-182/+805
| | | | | | | | | | | | 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)
* Add support for the 'x' mode option in fopen() as specified in the C1Xdas2011-10-212-49/+60
| | | | | | draft standard. The option is equivalent to O_EXCL. MFC after: 1 month
* Because we call __printf_out() with a on-stack buffer, also callpjd2011-03-061-2/+4
| | | | | | __printf_flush() so we are sure it won't be referenced after we return. MFC after: 2 weeks
* Fix various issues in how %#T is handled:pjd2011-03-061-7/+11
| | | | | | | | | | - If precision is 0, don't print period followed by no digits. - If precision is 0 stop printing units as soon as possible (eg. if we have three years and five days and precision is 0 print only 3y5d). - If precision is not 0, print all units (eg. 3y0d0h0m0s.00). MFC after: 2 weeks
* When reopening a stream backed by an open file descriptor, do not closejhb2010-12-091-12/+9
| | | | | | | | | | | | | the existing file descriptor. Instead, let dup2() atomically close the old file descriptor when assigning the newly opened file to the same descriptor. This closes a race in a multithreaded application where a concurrent open() could allocate the existing file descriptor in between the calls to close() and dup2(). PR: threads/79887 Submitted by: Dmitrij Tejblum tejblum of yandex-team.ru Reviewed by: davidxu MFC after: 1 week
* Remove two unused variables, left over from the refactoring in r180104.gavin2010-12-021-6/+0
| | | | | | PR: bin/152551 Submitted by: Henning Petersen <henning.petersen t-online.de> MFC after: 2 weeks
* Update the documentation to reflect changes to the implementation indas2010-11-301-14/+14
| | | | | | | r197752, which is related to handling of null buffer pointers. Also make a few minor wording changes. Reported by: jh@
* Revert changes of 'assure' to 'ensure' made in r211936.brucec2010-09-111-1/+1
| | | | Approved by: rrs (mentor)
* Fix incorrect usage of 'assure' and 'insure'.brucec2010-08-281-1/+1
| | | | Approved by: rrs (mentor)
* mdoc: move CAVEATS, BUGS and SECURITY CONSIDERATIONS sections to theuqs2010-05-134-98/+98
| | | | | | | | | | | bottom of the manpages and order them consistently. GNU groff doesn't care about the ordering, and doesn't even mention CAVEATS and SECURITY CONSIDERATIONS as common sections and where to put them. Found by: mdocml lint run Reviewed by: ru
* mdoc: fix parenthesisuqs2010-05-111-2/+2
| | | | Reviewed by: brueffer
* mdoc: use macro for +- that is understood by mdocmluqs2010-05-112-4/+4
| | | | Reviewed by: brueffer
* I feel this wording of the history is more clear.obrien2010-04-052-9/+6
| | | | ANSIfy vasprintf() while I'm here.
* - Use an initializer macro to initialize fields in 'fake' FILE objects usedjhb2010-03-1112-39/+22
| | | | | | | | | | | | by *sprintf(), etc. - Explicitly initialize _fl_mutex to PTHREAD_MUTEX_INITIALIZER for all FILE objects. This is currently a nop on FreeBSD, but is import for other platforms (or in the future) where PTHREAD_MUTEX_INITIALIZER is not simply zero. PR: threads/141198 Reported by: Jeremy Huddleston @ Apple MFC after: 2 weeks
* In _gettemp(), check that the length of the path doesn't exceedjh2010-02-281-0/+4
| | | | | | | | MAXPATHLEN. Otherwise the path name (or part of it) may not fit to carrybuf causing a buffer overflow. PR: bin/140228 Suggested by: jilles
* %U was macroized in mdoc(7), escape.ru2010-02-161-1/+1
|
* Give a less silly response to a silly request.cperciva2010-01-102-3/+40
| | | | | | | | | | | | | | | | | | | | | | | | | Prior to this commit, fread/fwrite calls with size * nmemb > SIZE_MAX were handled by reading or writing (size_t)(size * nmemb) bytes; for example, on 32-bit platforms, fread(ptr, 641, 6700417, f) would read 1 byte and indicate that the requested 6700417 blocks had been read. This commit adds a check for such integer overflows, and treats them as if an overly large request was passed to read/write; i.e., it sets errno to EINVAL, sets the error indicator on the file, and returns a short object count (0, to be specific). The overflow check involves an integer division, so as a performance optimization we check first to see if both size and nmemb are less than 2^16; if they are, no overflow is possible and we avoid the division. We assume here that size_t is at least 32 bits; this appears to be true on all platforms FreeBSD supports. Although this commit fixes an integer overflow, it is not likely to have any security implications, since any program which would be affected by this bug fix is quite clearly already very confused. Reviewed by: kib MFC after: 1 month
* Remove unnecessary quoting and markup, add missing punctuation.brueffer2010-01-081-3/+2
| | | | | | PR: 140494 Submitted by: Jeremy Huddleston <jeremyhu@apple.com>, bde MFC after: 1 week
* Use vsprintf instead of rolling our own.delphij2009-12-211-9/+1
| | | | | | PR: bin/140496 Submitted by: Jeremy Huddleston <jeremyhu apple.com> MFC after: 1 month
* Use vsscanf instead of rolling our own.delphij2009-12-211-24/+1
| | | | | | PR: bin/140530 Submitted by: Jeremy Huddleston <jeremyhu apple.com> MFC after: 1 month
* K&R -> ANSI prototype.delphij2009-12-211-8/+3
| | | | MFC after: 1 month
* (no commit message)matteo2009-12-161-1/+2
|
* Fix many "function declaration isn't a prototype" warnings in libc.ed2009-12-052-6/+6
| | | | | I've only fixed code that seems to be written by `us'. There are still many warnings like this present in resolv/, rpc/, stdtime/ and yp/.
* Fix the dprintf() prototype.brueffer2009-12-021-2/+2
| | | | | | PR: 141087 Submitted by: Jeremy Huddleston <jeremyhu@apple.com> MFC after: 3 days
* Eliminate more dead stores.wollman2009-11-251-1/+1
| | | | | Found by: Clang static analyzer MFC after: 7 days
* Make all three if conditions look similar by always initializing nsecwollman2009-11-251-1/+2
| | | | | | | | and moving the default initialization of prec into the else clause. The clang static analyzer erroneously thought that nsec can be used uninitialized here; it was not actually possible, but better to make the code clearer. (Clang can't know that sprintf() won't modify *pi behind the scenes.)
* In __mbsconv(), if prec was zero, nconv could have been usedwollman2009-11-251-1/+1
| | | | | | | | | 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
* Eliminate dead store.wollman2009-11-251-1/+1
| | | | | Found by: Clang static analyzer MFC after: 7 days
* Better glibc compatibility for getline/getdelim:das2009-10-041-2/+2
| | | | | | | | | | | | | | - Tolerate applications that pass a NULL pointer for the buffer and claim that the capacity of the buffer is nonzero. - If an application passes in a non-NULL buffer pointer and claims the buffer has zero capacity, we should free (well, realloc) it anyway. It could have been obtained from malloc(0), so failing to free it would be a small memory leak. MFC After: 2 weeks Reported by: naddy PR: ports/138320
* Make the description of `b' a little better.ed2009-09-091-1/+1
| | | | | | | If you have a one-byte sequence, `w', `b' is the second character. Not the third. Submitted by: Christoph Mallon
* Fix fwrite() to return 0 when size or nmemb are zero.ed2009-07-122-4/+9
| | | | | | | | Right now nmemb is returned when size is 0. In newer versions of the standards, it is explicitly required that fwrite() should return 0. Submitted by: Christoph Mallon Approved by: re (kib)
* Return -1 instead of 0 upon reaching EOF. This is somewhat ill-adviseddas2009-04-062-4/+6
| | | | | | | | because it means getdelim() returns -1 for both error and EOF, and never returns 0. However, this is what the original GNU implementation does, and POSIX inherited the bug. Reported by: marcus@
* Add dprintf() and vdprintf() from POSIX.1-2008. Like getline(),das2009-03-046-32/+198
| | | | | | dprintf() is a simple wrapper around another function, so we may as well implement it. But also like getline(), we can't prototype it by default right now because it would break too many ports.
* Rewrite asprintf() as a wrapper around vasprintf(), thus reducing thedas2009-03-021-43/+22
| | | | | number of functions that have an incestuous relationship with the arcane innards of stdio.
* The argument corresponding to %zn is supposed to be an ssize_t *, notdas2009-03-022-6/+6
| | | | a size_t *, although the distinction is moot in practice.
* Use C99-style initializers. No functional change.das2009-03-011-4/+9
| | | | Reviewed by: md5(1)
* Replace a dozen lines of code with a call to strnlen() / wcsnlen().das2009-02-282-33/+2
|
* - Add getdelim(), getline(), stpncpy(), strnlen(), wcsnlen(),das2009-02-288-5/+377
| | | | | | | | | | | | wcscasecmp(), and wcsncasecmp(). - Make some previously non-standard extensions visible if POSIX_VISIBLE >= 200809. - Use restrict qualifiers in stpcpy(). - Declare off_t and size_t in stdio.h. - Bump __FreeBSD_version in case the new symbols (particularly getline()) cause issues with ports. Reviewed by: standards@
* Make sure %zd treats negative arguments properly on 32-bit platforms.das2009-02-283-5/+8
| | | | | | | Fix harmless but related bugs in %_$zd and %_$tu. PR: 131880 MFC after: 1 week
* Better wording for clearing EOF indicator.trhodes2009-01-281-0/+4
| | | | Submitted by: keramida and jhb
OpenPOWER on IntegriCloud