Fix Print::printf return value on truncation and error#74
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.
This PR fixes Print::printf’s return value semantics by correctly handling vsnprintf’s “would-have-written” length on truncation and negative values on encoding errors (Fixes #72).
Changes:
- Store
vsnprintf’s return value asintand treat<= 0as no bytes written. - Clamp the output length to the buffer’s actual written capacity on truncation.
- Return the byte count from
write()instead of thevsnprintfwould-be length.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (n <= 0) return 0; | ||
| // vsnprintf returns the would-be length; clamp to what actually fit. | ||
| size_t len = (n < (int)sizeof(buf)) ? (size_t)n : sizeof(buf) - 1; | ||
| return write((const uint8_t *)buf, len); |
Print::printfreturns an incorrect byte count #72