Repository navigation
Conversation
Whether to truncate the file was decided by errno != ESPIPE also after a successful lseek()/fseek(), which does not change errno. With errno left at ESPIPE from before (for example by ly_out_reset() of an output writing to a pipe), the file was rewound but not truncated and the tail of the previous output remained after the new one.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
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.
ly_out_reset()is documented to make the following printer functions rewrite the output instead of appending, and for files to seek to the beginning and truncate them. For file descriptor, file stream and file path outputs it decides whether to truncate by testingerrno != ESPIPEeven when the seek succeeded. A successfullseek()/fseek()does not changeerrno, so iferrnohappens to beESPIPEbefore the call, the file is rewound but not truncated, and the tail of the previous output stays after the new one.On devel f45939c the file is
"second\nutput, longer\n"instead of"second\n".errnocan beESPIPEhere without the caller doing anything unusual:ly_out_reset()on an output writing to a pipe sets it and returns success, so a later reset of a file output in the same thread does not truncate.Fix: truncate only when the seek succeeded; a failed seek with
ESPIPEis still accepted as before. Thetest_output_fdandtest_output_filecases now seterrnotoESPIPEbefore the reset and check the length of the file; they fail on the current tree and pass with the fix.Tested on devel f45939c with clang 21,
-fsanitize=address,undefined,ENABLE_TESTS=ON:ctestpasses (70 tests).