Skip to content

Keep save_to_memory output contiguous after truncation - #14

Open
94xhn wants to merge 1 commit into
raysan5:mainfrom
94xhn:fix-save-to-memory-contiguous
Open

Keep save_to_memory output contiguous after truncation#14
94xhn wants to merge 1 commit into
raysan5:mainfrom
94xhn:fix-save-to-memory-contiguous

Conversation

@94xhn

@94xhn 94xhn commented Jul 19, 2026

Copy link
Copy Markdown

Keep rini_save_to_memory() output contiguous when a line is truncated

rini_save_to_memory() formats each entry with snprintf() and then advances an output offset. The previous code assumed every truncating implementation would return a value at least as large as RINI_MAX_LINE_SIZE. On MinGW, snprintf() returns -1 for 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:

  • MinGW GCC 8.1 baseline/fixed comparison with a maximum-sized key, value, description, and a following tail entry: baseline omits tail; fixed output retains it.
  • WSL GCC 13 baseline/fixed comparison: same behavioral difference.
  • Linux GCC 13 with AddressSanitizer and UndefinedBehaviorSanitizer: fixed case passes.
  • -Wall -Wextra -Werror compilation and git diff --check pass.

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
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.

1 participant