Keep save_to_memory output contiguous after truncation - #14
Open
94xhn wants to merge 1 commit into
Open
Conversation
When rini_save_to_memory() formats a line at the configured maximum, the next entry must start immediately after the bytes actually written. Account for both snprintf implementations that report the required length and MinGW implementations that return -1 on truncation. Constraint: Preserve the existing fixed-size memory-buffer API and single-header design Rejected: Advance by RINI_MAX_LINE_SIZE unconditionally | it leaves an embedded terminator between entries; treat only nonnegative short writes as the returned length Confidence: high Scope-risk: narrow Reversibility: clean Directive: Keep offset advancement tied to bytes present in the output buffer Tested: MinGW GCC 8.1 baseline/fixed harness; WSL GCC 13 baseline/fixed harness; Linux ASan/UBSan fixed harness; git diff --check Not-tested: Project has no in-tree automated test target Related: rini_save_to_memory output contract
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.
Keep
rini_save_to_memory()output contiguous when a line is truncatedrini_save_to_memory()formats each entry withsnprintf()and then advances an output offset. The previous code assumed every truncating implementation would return a value at least as large asRINI_MAX_LINE_SIZE. On MinGW,snprintf()returns-1for this case, so the offset was advanced incorrectly and later entries could disappear from the returned text.The offset now advances by the number of bytes actually present in the current output segment whenever the return value indicates truncation. Short, non-truncated writes continue to use the returned length.
Validation:
tailentry: baseline omitstail; fixed output retains it.-Wall -Wextra -Werrorcompilation andgit diff --checkpass.