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

stdio/file: fix numerous issues in the fread/fwrite functions #376

Merged
merged 2 commits into from
Oct 29, 2024

Conversation

ziemleszcz
Copy link
Contributor

@ziemleszcz ziemleszcz commented Aug 21, 2024

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@ziemleszcz ziemleszcz self-assigned this Aug 21, 2024
@ziemleszcz ziemleszcz force-pushed the ziemleszcz/RTOS-892 branch from bf2a36e to 7058c9c Compare August 21, 2024 12:53
Copy link

github-actions bot commented Aug 21, 2024

Unit Test Results

7 787 tests  +46   7 069 ✅ +43   40m 11s ⏱️ - 1m 25s
  461 suites ± 0     718 💤 + 3 
    1 files   ± 0       0 ❌ ± 0 

Results for commit 029ada8. ± Comparison against base commit de1e3a5.

♻️ This comment has been updated with latest results.

@ziemleszcz ziemleszcz changed the title Ziemleszcz/rtos 892 stdio/file: fix numerous issues in the fread/fwrite functions Aug 22, 2024
@ziemleszcz ziemleszcz marked this pull request as ready for review August 22, 2024 11:57
unistd/file.c Show resolved Hide resolved
@ziemleszcz ziemleszcz marked this pull request as draft September 23, 2024 13:55
Also fixed error handling in blocking safe write to return -1 in case of undefined behavior.

JIRA: RTOS-892, RTOS-874
stdio/file.c Outdated Show resolved Hide resolved
stdio/file.c Outdated Show resolved Hide resolved
@ziemleszcz ziemleszcz force-pushed the ziemleszcz/RTOS-892 branch 2 times, most recently from 0f3e3de to 5df66ae Compare October 14, 2024 07:20
@ziemleszcz ziemleszcz marked this pull request as ready for review October 14, 2024 09:09
stdio/file.c Show resolved Hide resolved
stdio/file.c Show resolved Hide resolved
return 0;
}
if (stream->bufpos != stream->bufeof) {
/* abort if the read buffer cannot be flushed (non-seekable stream) */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't errno be set then? (And maybe the error flag?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's implementation-specific behavior. In this case, I'm emulating glibc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, case similar to errno in malloc(0), so we probably can't solve this reasonably. Ack.

Darchiv
Darchiv previously approved these changes Oct 21, 2024
return 0;
}
if (stream->bufpos != stream->bufeof) {
/* abort if the read buffer cannot be flushed (non-seekable stream) */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, case similar to errno in malloc(0), so we probably can't solve this reasonably. Ack.

Fixed the following issues:
 - fclose returned -EINVAL instead of EOF
 - fclose did not return EOF on stream buffer flushing errors
 - removed unnecessary stream buffer flushing in fopen & fdopen
 - freopen did not return NULL on stream buffer flushing errors
 - fseek/fseeko/fsetpos cleared F_EOF flag on error
 - ftell/ftello/fgetpos cleared F_EOF flag
 - ftell/ftello/fgetpos flushed the stream buffer
 - non-blocking fflush was unsupported
 - flushing failed for non-seekable streams (lseek returning ESPIPE)
 - interleaved fread/fwrite failed for non-seekable streams (lseek returning ESPIPE)
 - non-blocking fread was unsupported
 - unbuffered fread did not set F_ERROR flag on read errors
 - unbuffered fread did not set F_EOF flag at end-of-file
 - buffered fread did not set F_ERROR flag on write buffer flushing errors
 - buffered fread did not return 0 on write buffer flushing errors
 - buffered fread did not set F_ERROR flag on buffer refilling errors
 - buffered fread incorrectly set F_EOF flag on EAGAIN errors
 - buffered fread did not always read full blocks from files
 - non-blocking fwrite was unsupported
 - unbuffered fwrite did not set F_ERROR flag on write errors
 - buffered fwrite did not set F_ERROR flag on read buffer flushing errors
 - buffered fwrite did not return 0 on read buffer flushing errors
 - buffered fwrite did not always write full blocks to files

JIRA: RTOS-892
@ziemleszcz ziemleszcz merged commit aefed2d into master Oct 29, 2024
36 checks passed
@ziemleszcz ziemleszcz deleted the ziemleszcz/RTOS-892 branch October 29, 2024 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants