Skip to content

sds: preserve input when printf growth fails - #82

Merged
edsiper merged 1 commit into
masterfrom
agent/sds-printf-preserve-input
Jul 11, 2026
Merged

sds: preserve input when printf growth fails#82
edsiper merged 1 commit into
masterfrom
agent/sds-printf-preserve-input

Conversation

@edsiper

@edsiper edsiper commented Jul 11, 2026

Copy link
Copy Markdown
Member

Summary

Restore the original SDS terminator before cfl_sds_printf() attempts to
grow its buffer.

Background

vsnprintf() writes a truncated result when the available capacity is
insufficient. If the subsequent allocation failed, cfl_sds_printf() returned
NULL while leaving bytes beyond the recorded SDS length modified and the
terminator invariant broken.

The original terminator is now restored before growth and on formatting
errors, so failure leaves the input SDS valid and unchanged from the caller's
perspective.

A regression test also covers appending formatted content to an existing
prefix while the SDS grows.

Validation

  • Focused SDS unit test
  • Full test suite: 34/34 passed
  • ASan/UBSan focused SDS test with leak detection
  • git diff --check

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
@edsiper
edsiper marked this pull request as ready for review July 11, 2026 17:19
@edsiper
edsiper merged commit 6b5f6fb into master Jul 11, 2026
22 checks passed
@edsiper
edsiper deleted the agent/sds-printf-preserve-input branch July 11, 2026 18:12
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