Fix fgets(..., size=1)#15
Closed
marxin wants to merge 1 commit into
Closed
Conversation
I noticed the following 2 tests are failing with -O1
-D_FORTIFY_SOURCE=1:
[ 44s] FAILED: whitespace-1.out: unifdef -DFOO whitespace.c
[ 44s] FAILED: whitespace-2.out: unifdef -DBAR whitespace.c
It's caused by fact that:
fgets returns '\0' if n == 1:
char *
_IO_fgets (char *buf, int n, FILE *fp)
{
size_t count;
char *result;
int old_error;
CHECK_FILE (fp, NULL);
if (n <= 0)
return NULL;
if (__glibc_unlikely (n == 1))
{
/* Another irregular case: since we have to store a NUL byte and
there is only room for exactly one byte, we don't have to
read anything. */
buf[0] = '\0';
return buf;
}
Author
|
Closing due to no action. |
|
@fanf2 Could you take a look? Thanks. |
Author
|
Please let me know if you are interested and if so, I'll reopen the pull request. |
gentoo-bot
pushed a commit
to gentoo/gentoo
that referenced
this pull request
May 10, 2025
The unifdef testsuite has been failing sometimes for years with _FORTIFY_SOURCE in a non-obvious way, where glibc's fgets will return \0 w/ n=1. I'd found marxin's PR for this years ago and apparently completely forgot about it (nor did I backport the patch into Gentoo at the time, as I didn't maintain it, and I was fairly new then). Backport marxin's patch from 2022 accordingly. Thanks to Ben Beasley poking me on the upstream PR (19) which made me look at all of this again. Bug: https://gcc.gnu.org/PR120205 Bug: fanf2/unifdef#15 Bug: fanf2/unifdef#19 Closes: https://bugs.gentoo.org/836698 Signed-off-by: Sam James <sam@gentoo.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I noticed the following 2 tests are failing with -O1
-D_FORTIFY_SOURCE=1:
[ 44s] FAILED: whitespace-1.out: unifdef -DFOO whitespace.c
[ 44s] FAILED: whitespace-2.out: unifdef -DBAR whitespace.c
It's caused by fact that:
fgets returns '\0' if n == 1: