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

Ensure C standard compliant fseek usage #298

Merged
merged 8 commits into from
Jun 3, 2024

Conversation

tim-griesbach
Copy link
Collaborator

Ensure C standard compliant fseek usage

According to the C standard (cf. https://wiki.sei.cmu.edu/confluence/display/c/FIO19-C.+Do+not+use+fseek()+and+ftell()+to+compute+the+size+of+a+regular+file), it can not be assumed that seeking to the end of a binary file works in general. However, this was done in p4est_save_ext. In concrete terms, the C standard states that

Setting the file position indicator to end-of-file, as with fseek(file, 0, SEEK_END), has undefined behavior for a binary stream (because of possible trailing null characters) or for any stream with state-dependent encoding that does not assuredly end in the initial shift state.

Proposed changes: This PR ensures that it is not necessary to seek to the end of a binary file by not closing the file in p4est_save_ext after the connectivity was written to disk.

@tim-griesbach
Copy link
Collaborator Author

I removed the occurrences of sink->file by using p4est_connectivity_sink in p4est_save_ext.

@tim-griesbach
Copy link
Collaborator Author

tim-griesbach commented Apr 17, 2024

sc_test_version failed in one CI test. This should be unrelated to the changes in this PR and transient.

Edit: Indeed, after rerunning the CI the failure disappeared.

@cburstedde cburstedde merged commit 12ca178 into cburstedde:develop Jun 3, 2024
17 checks passed
@tim-griesbach tim-griesbach deleted the fix-ftell-usage branch June 5, 2024 07:53
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