Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fread(a, b, 0, c) bug #52

Closed
steffengutmann opened this issue Dec 29, 2021 · 5 comments
Closed

fread(a, b, 0, c) bug #52

steffengutmann opened this issue Dec 29, 2021 · 5 comments
Assignees
Labels
priority:default type:bug Something isn't working
Projects

Comments

@steffengutmann
Copy link

A call to fread(buffer, size, 0, file) sets the EOF flag of the file descriptor. This is because of how AROS/compiler/posixc/fread.c (https://github.com/aros-development-team/AROS/blob/master/compiler/posixc/fread.c) is implemented:

Code: [Select]

else if (cnt == 0 || cnt < nblocks)
{
stream->flags |= __POSIXC_STDIO_EOF;
}

The fix would be to change the condition to "else if (cnt < nblocks)" only, or do an early return 0 similar to how it is done in AROS/compiler/stdc/fread.c

Of course, it is easy to work around this by simply not calling fread when there is nothing to be read.

Attached is a test case including how to reproduce and the output on Linux and AROS.

fread.c.txt

@deadwood2 deadwood2 added priority:default type:bug Something isn't working labels Dec 29, 2021
@deadwood2 deadwood2 self-assigned this Jan 9, 2022
@deadwood2
Copy link
Owner

@steffengutmann Do you need fix for this ported to ABIv0 as well?

@steffengutmann
Copy link
Author

Absolutely.

But please note that I am not developing for AROS, just making my SW available for AROS. And I have already worked-around this problem in my SW. But I would not be surprised if other SW also runs into this same bug.

@deadwood2
Copy link
Owner

Ok, understood. The fix will make it to ABIv0 but it will take some time before it is included in distributions.

@steffengutmann
Copy link
Author

steffengutmann commented Jan 13, 2022 via email

deadwood2 pushed a commit that referenced this issue Jan 13, 2022
@deadwood2
Copy link
Owner

Fixed in 1d67ef5

deadwood2 pushed a commit that referenced this issue Jan 19, 2022
deadwood2 pushed a commit to deadwood2/fork-ADT-AROS that referenced this issue May 4, 2022
deadwood2 pushed a commit to deadwood2/fork-ADT-AROS that referenced this issue May 9, 2022
deadwood2 pushed a commit that referenced this issue May 28, 2022
deadwood2 pushed a commit that referenced this issue Jun 16, 2022
deadwood2 pushed a commit that referenced this issue Jan 17, 2023
deadwood2 pushed a commit that referenced this issue Jan 21, 2023
deadwood2 pushed a commit that referenced this issue Jan 24, 2023
deadwood2 pushed a commit that referenced this issue Feb 10, 2023
deadwood2 pushed a commit that referenced this issue Dec 5, 2023
deadwood2 pushed a commit that referenced this issue Dec 19, 2023
deadwood2 pushed a commit that referenced this issue Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:default type:bug Something isn't working
Projects
Core
Awaiting triage
Development

No branches or pull requests

2 participants