aboutsummaryrefslogtreecommitdiff
path: root/stdio-common
AgeCommit message (Collapse)AuthorFilesLines
5 daysstdio-common: In tst-setvbuf2, close helper thread descriptor only if openedFlorian Weimer1-18/+21
The helper thread may get canceled before the open system call succeds. Then ThreadData.fd remains zero, and eventually the xclose call in end_reader_thread fails because descriptor 0 is not open. Instead, initialize the fd member to -1 (not a valid descriptor) and close the descriptor only if valid. Do this in a new end_thread helper routine. Also add more error checking to close operations. Fixes commit 95b780c1d0549678c0a244c6e2112ec97edf0839 ("stdio: Add more setvbuf tests").
11 daysstdio: fix hurd link for tst-setvbuf2DJ Delorie1-1/+2
12 daysstdio: Add more setvbuf testsDJ Delorie3-1/+1041
2025-03-28stdio-common: Reject real data w/o exponent digits in scanf [BZ #12701]Maciej W. Rozycki2-3/+6
Reject invalid formatted scanf real input data the exponent part of which is comprised of an exponent introducing character, optionally followed by a sign, and with no actual digits following. Such data is a prefix of, but not a matching input sequence and it is required by ISO C to cause a matching failure. Currently a matching success is instead incorrectly produced along with the conversion result according to the input significand read and the exponent of zero, with the significand and the exponent part wholly consumed from input. Correct an invalid `tstscanf.c' test accordingly that expects a matching success for input data provided in the ISO C standard as an example for a matching failure. Enable input data that causes test failures without this fix in place. Reviewed-by: Joseph Myers <josmyers@redhat.com>
2025-03-28stdio-common: Reject significand prefixes in scanf [BZ #12701]Maciej W. Rozycki1-1/+6
Reject invalid formatted scanf real input data that is comprised of a hexadecimal prefix, optionally preceded by a sign, and with no actual digits following owing to the field width restriction in effect. Such data is a prefix of, but not a matching input sequence and it is required by ISO C to cause a matching failure. Currently a matching success is instead incorrectly produced along with the conversion result of zero, with the prefix wholly consumed from input. Where the end of input is marked by the end-of-file condition rather than the field width restriction in effect a matching failure is already correctly produced. Enable input data that causes test failures without this fix in place. Reviewed-by: Joseph Myers <josmyers@redhat.com>
2025-03-28stdio-common: Reject integer prefixes in scanf [BZ #12701]Maciej W. Rozycki13-937/+947
Reject invalid formatted scanf integer input data that is comprised of a binary or hexadecimal prefix, optionally preceded by a sign, and with no actual digits following. Such data is a prefix of, but not a matching input sequence and it is required by ISO C to cause a matching failure. Currently a matching success is instead incorrectly produced along with the conversion result of zero, with the prefix wholly consumed from input. Enable input data that causes test failures without this fix in place. Reviewed-by: Joseph Myers <josmyers@redhat.com>
2025-03-28stdio-common: Also reject exp char w/o significand in i18n scanf [BZ #13988]Maciej W. Rozycki1-3/+9
Fix the handling of real 'scanf' input such as "+.e" as per BZ #13988 for the i18n case as well, complementing commit 6ecec3b616ae ("Don't accept exp char without preceding digits in scanf float parsing"), where the 'e' character is incorrectly consumed from input. Add a test case matching stdio-common/bug26.c, with bits from localedata/tst-sscanf.c. Reviewed-by: Joseph Myers <josmyers@redhat.com>
2025-03-28stdio-common: Add tests for formatted vsscanf input specifiersMaciej W. Rozycki16-1/+386
Wire vsscanf into test infrastructure for formatted scanf input specifiers. Reviewed-by: Joseph Myers <josmyers@redhat.com>
2025-03-28stdio-common: Add tests for formatted vfscanf input specifiersMaciej W. Rozycki16-1/+345
Wire vfscanf into test infrastructure for formatted scanf input specifiers. Reviewed-by: Joseph Myers <josmyers@redhat.com>
2025-03-28stdio-common: Add tests for formatted vscanf input specifiersMaciej W. Rozycki16-1/+345
Wire vscanf into test infrastructure for formatted scanf input specifiers. Reviewed-by: Joseph Myers <josmyers@redhat.com>
2025-03-28stdio-common: Add tests for formatted sscanf input specifiersMaciej W. Rozycki16-1/+382
Wire sscanf into test infrastructure for formatted scanf input specifiers. Reviewed-by: Joseph Myers <josmyers@redhat.com>
2025-03-28stdio-common: Add tests for formatted fscanf input specifiersMaciej W. Rozycki16-1/+338
Wire fscanf into test infrastructure for formatted scanf input specifiers. Reviewed-by: Joseph Myers <josmyers@redhat.com>
2025-03-25stdio-common: Add tests for formatted scanf input specifiersMaciej W. Rozycki59-0/+15485
Add a collection of tests for formatted scanf input specifiers covering the b, d, i, o, u, x, and X integer conversions, the a, A, e, E, f, F, g, and G floating-point conversions, and the [, c, and s character conversions. Also the hh, h, l, and ll length modifiers are covered with the integer conversions as are the l and L length modifier with the floating-point conversions. The tests cover assignment suppressing and the field width as well, verifying the number of assignments made, the number of characters consumed and the value assigned. Add the common test code here as well as test cases for scanf, and then base Makefile infrastructure plus target-agnostic input data, for the character conversions and the `char', `short', and `long long' integer ones, signed and unsigned, with remaining input data and other functions from the scanf family deferred to subsequent additions. Keep input data disabled and referring to BZ #12701 for entries that are currently incorrectly accepted as valid data, such as '0b' or '0x' with the relevant integer conversions or sequences of an insufficient number of characters with the c conversion. Reviewed-by: Joseph Myers <josmyers@redhat.com>
2025-03-21debug: Improve '%n' fortify detection (BZ 30932)Adhemerval Zanella2-15/+22
The 7bb8045ec0 path made the '%n' fortify check ignore EMFILE errors while trying to open /proc/self/maps, and this added a security issue where EMFILE can be attacker-controlled thus making it ineffective for some cases. The EMFILE failure is reinstated but with a different error message. Also, to improve the false positive of the hardening for the cases where no new files can be opened, the _dl_readonly_area now uses _dl_find_object to check if the memory area is within a writable ELF segment. The procfs method is still used as fallback. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Arjun Shankar <arjun@redhat.com>
2025-03-13elf: Canonicalize $ORIGIN in an explicit ld.so invocation [BZ 25263]Adhemerval Zanella3-43/+62
When an executable is invoked directly, we calculate $ORIGIN by calling readlink on /proc/self/exe, which the Linux kernel resolves to the target of any symlinks. However, if an executable is run through ld.so, we cannot use /proc/self/exe and instead use the path given as an argument. This leads to a different calculation of $ORIGIN, which is most notable in that it causes ldd to behave differently (e.g., by not finding a library) from directly running the program. To make the behavior consistent, take advantage of the fact that the kernel also resolves /proc/self/fd/ symlinks to the target of any symlinks in the same manner, so once we have opened the main executable in order to load it, replace the user-provided path with the result of calling readlink("/proc/self/fd/N"). (On non-Linux platforms this resolution does not happen and so no behavior change is needed.) The __fd_to_filename requires _fitoa_word and _itoa_word, which for 32-bits pulls a lot of definitions from _itoa.c (due _ITOA_NEEDED being defined). To simplify the build move the required function to a new file, _fitoa_word.c. Checked on x86_64-linux-gnu and i686-linux-gnu. Co-authored-by: Geoffrey Thomas <geofft@ldpreload.com> Reviewed-by: Geoffrey Thomas <geofft@ldpreload.com> Tested-by: Geoffrey Thomas <geofft@ldpreload.com>
2025-02-24Increase the amount of data tested in stdio-common/tst-fwrite-pipe.cStefan Liebler1-2/+2
The number of iterations and the length of the string are not high enough on some systems causing the test to return false-positives. Testcase stdio-common/tst-fwrite-bz29459.c was fixed in the same way in 1b6f868625403d6b7683af840e87d2b18d5d7731 (Increase the amount of data tested in stdio-common/tst-fwrite-bz29459.c, 2025-02-14) Testcases stdio-common/tst-fwrite-bz29459.c and stdio-common/tst-fwrite-pipe.c were introcued in 596a61cf6b51ce2d58b8ca4e1d1f4fdfe1440dbc (libio: Start to return errors when flushing fwrite's buffer [BZ #29459], 2025-01-28)
2025-02-14Increase the amount of data tested in stdio-common/tst-fwrite-bz29459.cTulio Magno Quites Machado Filho1-2/+2
The number of iterations and the length of the string are not high enough on some systems causing the test to return false-positives. Fixes: 596a61cf6b (libio: Start to return errors when flushing fwrite's buffer [BZ #29459], 2025-01-28) Reported-by: Florian Weimer <fweimer@redhat.com>
2025-01-28Add test of input file flushing / offset issuesJoseph Myers2-0/+561
Having fixed several bugs relating to flushing of FILE* streams (with fflush and other operations) and their offsets (both the file position indicator in the FILE*, and the offset in the underlying open file description), especially after ungetc but not limited to that case, add a test that more systematically covers different combinations of cases for such issues, with 57220 separate scenarios tested (which include examples of all the five separate fixed bugs), all of which pass given the five previous bug fixes. Tested for x86_64.
2025-01-28Fix fflush handling for mmap files after ungetc (bug 32535)Joseph Myers2-0/+51
As discussed in bug 32535, fflush fails on files opened for reading using mmap after ungetc. Fix the logic to handle this case and still compute the file offset correctly. Tested for x86_64.
2025-01-28Fix fseek handling for mmap files after ungetc or fflush (bug 32529)Joseph Myers2-0/+60
As discussed in bug 32529, fseek fails on files opened for reading using mmap after ungetc. The implementation of fseek for such files has an offset computation that's also incorrect after fflush. A combined fix addresses both problems (with tests for both included as well) and it seems reasonable to consider them a single bug. Tested for x86_64.
2025-01-28Make fflush (NULL) flush input files (bug 32369)Joseph Myers2-0/+95
As discussed in bug 32369 and required by POSIX, the POSIX feature fflush (NULL) should flush input files, not just output files. The POSIX requirement is that "fflush() shall perform this flushing action on all streams for which the behavior is defined above", and the definition for input files is for "a stream open for reading with an underlying file description, if the file is not already at EOF, and the file is one capable of seeking". Implement this requirement in glibc. (The underlying flushing implementation is what deals with avoiding errors for seeking on an unseekable file.) Tested for x86_64.
2025-01-28Make fclose seek input file to right offset (bug 12724)Joseph Myers2-0/+226
As discussed in bug 12724 and required by POSIX, before an input file (based on an underlying seekable file descriptor) is closed, fclose is sometimes required to seek that file descriptor to the correct offset, so that any other file descriptors sharing the underlying open file description are left at that offset (as a motivating example, a script could call a sequence of commands each of which processes some data from (seekable) stdin using stdio; fclose needs to do this so that each successive command can read exactly the data not handled by previous commands), but glibc fails to do this. The precise POSIX wording has changed a few times; in the 2024 edition it's "If the file is not already at EOF, and the file is one capable of seeking, the file offset of the underlying open file description shall be set to the file position of the stream if the stream is the active handle to the underlying file description.". Add appropriate logic to _IO_new_file_close_it to handle this case. I haven't made any attempt to test or change things in this area for the "old" functions. Note that there was a previous attempt to fix bug 12724, reverted in commit eb6cbd249f4465b01f428057bf6ab61f5f0c07e3. The fix version here addresses the original test in that bug report without breaking the one given in a subsequent comment in that bug report (which works with glibc before the patch, but maybe was broken by the original fix that was reverted). The logic here tries to take care not to seek the file, even to its newly computed current offset, if at EOF / possibly not the active handle; even seeking to the current offset would be problematic because of a potential race (fclose computes the current offset, another thread or process with the active handle does its own seek, fclose does a seek (not permitted by POSIX in this case) that loses the effect of the seek on the active handle in another thread or process). There are tests included for various cases of being or not being the active handle, though there aren't tests for the potential race condition. Tested for x86_64.
2025-01-28Fix fflush after ungetc on input file (bug 5994)Joseph Myers2-0/+65
As discussed in bug 5994 (plus duplicates), POSIX requires fflush after ungetc to discard pushed-back characters but preserve the file position indicator. For this purpose, each ungetc decrements the file position indicator by 1; it is unspecified after ungetc at the start of the file, and after ungetwc, so no special handling is needed for either of those cases. This is fixed with appropriate logic in _IO_new_file_sync. I haven't made any attempt to test or change things in this area for the "old" functions; the case of files using mmap is addressed in a subsequent patch (and there seem to be no problems in this area with files opened with fmemopen). Tested for x86_64.
2025-01-28libio: Add a new fwrite test that evaluates partial writesTulio Magno Quites Machado Filho2-0/+234
Test if the file-position is correctly updated when fwrite tries to flush its internal cache but is not able to completely write all items. Reviewed-by: DJ Delorie <dj@redhat.com>
2025-01-28libio: Start to return errors when flushing fwrite's buffer [BZ #29459]Tulio Magno Quites Machado Filho4-0/+260
When an error happens, fwrite is expected to return a value that is less than nmemb. If this error happens while flushing its internal buffer, fwrite is in a complex scenario: all the data might have been written to the buffer, indicating a successful copy, but the buffer is expected to be flushed and it was not. POSIX.1-2024 states the following about errors on fwrite: If an error occurs, the resulting value of the file-position indicator for the stream is unspecified. The fwrite() function shall return the number of elements successfully written, which may be less than nitems if a write error is encountered. With that in mind, this commit modifies _IO_new_file_write in order to return the total number of bytes written via the file pointer. It also modifies fwrite in order to use the new information and return the correct number of bytes written even when sputn returns EOF. Add 2 tests: 1. tst-fwrite-bz29459: This test is based on the reproducer attached to bug 29459. In order to work, it requires to pipe stdout to another process making it hard to reuse test-driver.c. This code is more specific to the issue reported. 2. tst-fwrite-pipe: Recreates the issue by creating a pipe that is shared with a child process. Reuses test-driver.c. Evaluates a more generic scenario. Co-authored-by: Florian Weimer <fweimer@redhat.com> Reviewed-by: DJ Delorie <dj@redhat.com>
2025-01-28Add new tests for fopenMartin Coufal2-0/+280
Adding some basic tests for fopen, testing different modes, stream positioning and concurrent read/write operation on files. Reviewed-by: DJ Delorie <dj@redhat.com>
2025-01-26testsuite: Make stdio-common/tst-printf-format-*-mem UNSUPPORTED if the ↵Xi Ruoyao1-2/+5
mtrace output does not exist When gawk was not built with MPFR, there's no mtrace output and those tests FAIL. But we should make them UNSUPPORTED like other tst-printf-format-* tests in the case. Signed-off-by: Xi Ruoyao <xry111@xry111.site> Reviewed-by: Sam James <sam@gentoo.org> Reviewed-by: Andreas K Hüttel <dilfridge@gentoo.org>
2025-01-13stdio-common: Suppress Clang warnings on scanf13.c with fortify enableAdhemerval Zanella1-0/+5
clang-19 shows: scanf13.c:28:40: error: 'sscanf' may overflow; destination buffer in argument 4 has size 8, but the corresponding specifier may require size 11 [-Werror,-Wfortify-source] 28 | "A%ms%10ms%4m[bcd]%4mcB", &sp1, &sp2, &sp3, &sp4) != 4) | ^ scanf13.c:94:34: error: 'sscanf' may overflow; destination buffer in argument 3 has size 8, but the corresponding specifier may require size 2049 [-Werror,-Wfortify-source] 94 | if (sscanf (buf, "%2048ms%mc", &sp3, &sp4) != 2) | ^ scanf13.c:110:61: error: 'sscanf' may overflow; destination buffer in argument 4 has size 8, but the corresponding specifier may require size 1501 [-Werror,-Wfortify-source] 110 | if (sscanf (buf, "%4mc%1500m[dr/]%548m[abc/d]%3mc", &sp1, &sp2, &sp3, &sp4) | ^ scanf13.c:110:67: error: 'sscanf' may overflow; destination buffer in argument 5 has size 8, but the corresponding specifier may require size 549 [-Werror,-Wfortify-source] 110 | if (sscanf (buf, "%4mc%1500m[dr/]%548m[abc/d]%3mc", &sp1, &sp2, &sp3, &sp4) clang does have some support to handle 'm' prefix for -Wformat; but it lacks support for -Wfortify to understand that it is up to libc to allocate the memory, and uses the pointer size instead to calculate validity.
2025-01-01Update copyright dates with scripts/update-copyrightsPaul Eggert410-411/+410
2024-12-24stdio-common: Tweak comment in MakefileSam James1-3/+3
Followup to 5a96da210c15e18c3c5298dc23a9e2e57691b6c6.
2024-12-24stdio-common: Use clang with bugfix for bug28Dmitry Chestnykh1-4/+4
The issue that was the cause of hang was fixed in upstream. Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
2024-12-23stdio-common: Suppress Clang warnings on scanf13.cH.J. Lu2-0/+11
Suppress Clang warnings on stdio-common/scanf13.c: 1. Before this commit: scanf13.c:43:17: error: invalid conversion specifier 'l' [-Werror,-Wformat-invalid-specifier] 43 | "A%mS%10mls%4ml[bcd]%4mCB", &lsp1, &lsp2, &lsp3, &lsp4) != 4) | ~~~~^ scanf13.c:43:22: error: invalid conversion specifier 'l' [-Werror,-Wformat-invalid-specifier] 43 | "A%mS%10mls%4ml[bcd]%4mCB", &lsp1, &lsp2, &lsp3, &lsp4) != 4) | ~~~~^ scanf13.c:43:50: error: data argument not used by format string [-Werror,-Wformat-extra-args] 43 | "A%mS%10mls%4ml[bcd]%4mCB", &lsp1, &lsp2, &lsp3, &lsp4) != 4) | ~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ scanf13.c:145:27: error: invalid conversion specifier 'l' [-Werror,-Wformat-invalid-specifier] 145 | if (sscanf (buf, "%2048mls%mlc", &lsp3, &lsp4) != 2) | ~~~~~~^ scanf13.c:145:31: error: invalid conversion specifier 'l' [-Werror,-Wformat-invalid-specifier] 145 | if (sscanf (buf, "%2048mls%mlc", &lsp3, &lsp4) != 2) | ~~~^ scanf13.c:145:43: error: data argument not used by format string [-Werror,-Wformat-extra-args] 145 | if (sscanf (buf, "%2048mls%mlc", &lsp3, &lsp4) != 2) | ~~~~~~~~~~~~~~ ^ scanf13.c:161:31: error: invalid conversion specifier 'l' [-Werror,-Wformat-invalid-specifier] 161 | if (sscanf (buf, "%4mC%1500ml[dr/]%548ml[abc/d]%3mlc", | ~~~~~~^ scanf13.c:161:42: error: invalid conversion specifier 'l' [-Werror,-Wformat-invalid-specifier] 161 | if (sscanf (buf, "%4mC%1500ml[dr/]%548ml[abc/d]%3mlc", | ~~~~~~~~~~^ scanf13.c:161:53: error: invalid conversion specifier 'l' [-Werror,-Wformat-invalid-specifier] 161 | if (sscanf (buf, "%4mC%1500ml[dr/]%548ml[abc/d]%3mlc", | ~~~~~~~~~~^ scanf13.c:162:15: error: data argument not used by format string [-Werror,-Wformat-extra-args] 161 | if (sscanf (buf, "%4mC%1500ml[dr/]%548ml[abc/d]%3mlc", | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 162 | &lsp1, &lsp2, &lsp3, &lsp4) != 4) | ^ 10 errors generated. 2. With DIAG_IGNORE_NEEDS_COMMENT_CLANG changes in stdio-common/scanf13.c: scanf13.c:28:40: error: 'sscanf' may overflow; destination buffer in argument 4 has size 8, but the corresponding specifier may require size 11 [-Werror,-Wfortify-source] 28 | "A%ms%10ms%4m[bcd]%4mcB", &sp1, &sp2, &sp3, &sp4) != 4) | ^ scanf13.c:94:34: error: 'sscanf' may overflow; destination buffer in argument 3 has size 8, but the corresponding specifier may require size 2049 [-Werror,-Wfortify-source] 94 | if (sscanf (buf, "%2048ms%mc", &sp3, &sp4) != 2) | ^ scanf13.c:110:61: error: 'sscanf' may overflow; destination buffer in argument 4 has size 8, but the corresponding specifier may require size 1501 [-Werror,-Wfortify-source] 110 | if (sscanf (buf, "%4mc%1500m[dr/]%548m[abc/d]%3mc", &sp1, &sp2, &sp3, &sp4) | ^ scanf13.c:110:67: error: 'sscanf' may overflow; destination buffer in argument 5 has size 8, but the corresponding specifier may require size 549 [-Werror,-Wfortify-source] 110 | if (sscanf (buf, "%4mc%1500m[dr/]%548m[abc/d]%3mc", &sp1, &sp2, &sp3, &sp4) | ^ 4 errors generated. Co-Authored-By: Adhemerval Zanella <adhemerval.zanella@linaro.org> Signed-off-by: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Sam James <sam@gentoo.org>
2024-12-23stdio: Suppress -Wformat only for gcc in tst-sprintf-errno.cAdhemerval Zanella1-1/+1
Since Clang doesn't support DIAG_IGNORE_NEEDS_COMMENT (11, "-Wformat="); and for unknown reasons, it doesn't warn the %#m specifier, suppress -Wformat only for gcc in tst-sprintf-errno.c. Co-Authored-By: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Sam James <sam@gentoo.org>
2024-12-22stdio: Suppress clang warnings for tst-vprintf-width-i18n.cAdhemerval Zanella1-0/+8
Clang issues the following warning: tst-vfprintf-width-i18n.c:51:34: error: invalid conversion specifier '1' [-Werror,-Wformat-invalid-specifier] TEST_COMPARE (sprintf (buf, "%I16d", 12345), 16); ~~^ since it does not how to handle %I. Reviewed-by: Sam James <sam@gentoo.org>
2024-12-22stdio: Fix clang warnings on testsAdhemerval Zanella1-0/+5
clang does not support 'I' specifier and handles it as a 'length modifier'. Reviewed-by: Sam James <sam@gentoo.org>
2024-12-22stdio: Suppress %Z format for clangAdhemerval Zanella5-0/+35
clang does not handle %Z on print, and just suppressing -Wformat-invalid-specifier might trigger another warning for extra arguments (since %Z is ignored). So suppress -Wformat-extra-args as well. For tst-fphex.c a heavy hammer is used since the printf is more complex and clang throws a more generic warning. Reviewed-by: Sam James <sam@gentoo.org>
2024-12-22stdio: Suppress clang warnings for tst-unlockedio.cAdhemerval Zanella1-0/+7
Suppress the following -Wgnu-folding-constant and -Wliteral-conversion warnings from Clang: tst-unlockedio.c:35:12: error: variable length array folded to constant array as an extension [-Werror,-Wgnu-folding-constant] 35 | char buf[strlen (blah) + 1]; | ^~~~~~~~~~~~~~~~~ tst-unlockedio.c:63:36: error: implicit conversion from 'double' to 'size_t' (aka 'unsigned long') changes value from -0 to 0 [-Werror,-Wliteral-conversion] || fwrite_unlocked (blah, 0, -0.0, fp) != 0 ~~~~~~~~~~~~~~~ ^~~~ tst-unlockedio.c:61:33: error: implicit conversion from 'double' to 'size_t' (aka 'unsigned long') changes value from 0.25 to 0 [-Werror,-Wliteral-conversion] || fwrite_unlocked (--cp, 0.25, 16, fp) != 0 ~~~~~~~~~~~~~~~ ^~~~ tst-unlockedio.c:59:37: error: implicit conversion from 'double' to 'size_t' (aka 'unsigned long') changes value from 0.25 to 0 [-Werror,-Wliteral-conversion] || fwrite_unlocked (cp++, 16, 0.25, fp) != 0 ~~~~~~~~~~~~~~~ ^~~~ tst-unlockedio.c:116:34: error: implicit conversion from 'double' to 'size_t' (aka 'unsigned long') changes value from -0 to 0 [-Werror,-Wliteral-conversion] || fread_unlocked (buf, 0, -0.0, fp) != 0 ~~~~~~~~~~~~~~ ^~~~ tst-unlockedio.c:114:32: error: implicit conversion from 'double' to 'size_t' (aka 'unsigned long') changes value from 0.25 to 0 [-Werror,-Wliteral-conversion] || fread_unlocked (--wp, 0.25, 16, fp) != 0 ~~~~~~~~~~~~~~ ^~~~ tst-unlockedio.c:112:36: error: implicit conversion from 'double' to 'size_t' (aka 'unsigned long') changes value from 0.25 to 0 [-Werror,-Wliteral-conversion] || fread_unlocked (wp++, 16, 0.25, fp) != 0 ~~~~~~~~~~~~~~ ^~~~ Co-Authored-By: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Sam James <sam@gentoo.org>
2024-12-22tst-printf-bz18872.sh: stdio: Use __attribute__ ((optnone)) for ClangAdhemerval Zanella1-0/+4
Use __attribute__ ((optnone)) instead of __attribute__ ((optimize ("-O0"))) to disable optimization for Clang. Co-Authored-By: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Sam James <sam@gentoo.org>
2024-12-21stdio-common: Exclude bug28 when clang is usedH.J. Lu1-1/+10
Clang 19 takes a very long time, it ran more than 27 minutes on Intel Core i7-1195G7 before the process was killed, to compile bug28.c: https://github.com/llvm/llvm-project/issues/120462 Exclude it when Clang is used for testing. Signed-off-by: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Sam James <sam@gentoo.org>
2024-12-17ungetc: Guarantee single char pushbackSiddhesh Poyarekar2-0/+123
The C standard requires that ungetc guarantees at least one pushback, but the malloc call to allocate the pushback buffer could fail, thus violating that requirement. Fix this by adding a single byte pushback buffer in the FILE struct that the pushback can fall back to if malloc fails. The side-effect is that if the initial malloc fails and the 1-byte fallback buffer is used, future resizing (if it succeeds) will be 2-bytes, 4-bytes and so on, which is suboptimal but it's after a malloc failure, so maybe even desirable. A future optimization here could be to have the pushback code use the single byte buffer first and only fall back to malloc for subsequent calls. Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org> Reviewed-by: Maciej W. Rozycki <macro@redhat.com>
2024-12-18Replace copysign (0,-1) with -0.0 in initializerH.J. Lu2-2/+2
GCC 4.9 issues an error for copysign in initializer: In file included from tst-printf-format-p-double.c:20:0: tst-printf-format-skeleton-double.c:29:3: error: initializer element is not a constant expression [-Werror] { -HUGE_VAL, -DBL_MAX, -DBL_MIN, copysign (0, -1), -NAN, NAN, 0, DBL_MIN, ^ since it can't fold "copysign (0, -1)". Replace copysign (0,-1) with -0.0. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-11-25Silence most -Wzero-as-null-pointer-constant diagnosticsAlejandro Colomar1-1/+1
Replace 0 by NULL and {0} by {}. Omit a few cases that aren't so trivial to fix. Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117059> Link: <https://software.codidact.com/posts/292718/292759#answer-292759> Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-15stdio-common: Fix C23-ism in formatted output specifier tests [BZ #32360]Maciej W. Rozycki1-1/+1
Nameless function parameters have only been added to ISO C with the C23 revision of the language standard. Give names to the unused parameters of the stub 'dladdr' implementation then so as to make compilation happy with the earlier language definitions, fixing errors such as: tst-printf-format-skeleton.c:374:9: error: parameter name omitted 374 | dladdr (const void *, Dl_info *) reported by older compilers. Reviewed-by: Florian Weimer <fweimer@redhat.com>
2024-11-07stdio-common: Add tests for formatted vsnprintf output specifiersMaciej W. Rozycki16-1/+345
Wire vsnprintf into test infrastructure for formatted printf output specifiers. Reviewed-by: DJ Delorie <dj@redhat.com>
2024-11-07stdio-common: Add tests for formatted vsprintf output specifiersMaciej W. Rozycki16-1/+345
Wire vsprintf into test infrastructure for formatted printf output specifiers. Reviewed-by: DJ Delorie <dj@redhat.com>
2024-11-07stdio-common: Add tests for formatted vfprintf output specifiersMaciej W. Rozycki16-1/+315
Wire vfprintf into test infrastructure for formatted printf output specifiers. Reviewed-by: DJ Delorie <dj@redhat.com>
2024-11-07stdio-common: Add tests for formatted vdprintf output specifiersMaciej W. Rozycki16-1/+343
Wire vdprintf into test infrastructure for formatted printf output specifiers. Reviewed-by: DJ Delorie <dj@redhat.com>
2024-11-07stdio-common: Add tests for formatted vasprintf output specifiersMaciej W. Rozycki16-1/+335
Wire vasprintf into test infrastructure for formatted printf output specifiers. Owing to mtrace logging these tests take amounts of time to complete similar to those of corresponding asprintf tests, so set timeouts for the tests accordingly, with a global default for all the vasprintf tests, and then individual higher settings for double and long double tests each. Reviewed-by: DJ Delorie <dj@redhat.com>
2024-11-07stdio-common: Add tests for formatted vprintf output specifiersMaciej W. Rozycki16-1/+315
Wire vprintf into test infrastructure for formatted printf output specifiers. Reviewed-by: DJ Delorie <dj@redhat.com>
2024-11-07stdio-common: Add tests for formatted snprintf output specifiersMaciej W. Rozycki16-1/+341
Wire snprintf into test infrastructure for formatted printf output specifiers. Reviewed-by: DJ Delorie <dj@redhat.com>