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

fgets fails to detect EOF #37

Open
lennart-benschop opened this issue Jul 9, 2024 · 1 comment
Open

fgets fails to detect EOF #37

lennart-benschop opened this issue Jul 9, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@lennart-benschop
Copy link

Found this when using fgets to read the config file in the 'mc' program.

When fgets reaches the end of file, it should return a NULL pointer. This works in the fab-agon-emulator, but it does not work on real hardware. The file has CRLF line endings and the last line ends with CRLF too.

fgets can read thousands of spurious lines before it finally thinks the end of file is reached for real. This increased the startup time of mc for some users to 2 minutes.

Temporary work-around: use my own function to read lines, based on fread(). fread() is known to reliably detect end of file.

FILE was opened using fopen with "r" mode ("r" for read access, text files). This converts CRLF on input to LF.

@sijnstra
Copy link
Contributor

sijnstra commented Aug 5, 2024

Same. I had code that worked on the emulator but not on real hardware with the same issue - ran out of memory due to reading phantom lines.

@astralaster astralaster added the bug Something isn't working label Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants