Skip to content

Remove sprintf usage and String double buffering - #286

Open
ayushfaujdar wants to merge 3 commits into
arduino:masterfrom
ayushfaujdar:sprintf-cleanup
Open

ayushfaujdar wants to merge 3 commits into
arduino:masterfrom
ayushfaujdar:sprintf-cleanup

Conversation

@ayushfaujdar

Copy link
Copy Markdown

Fixes #209
Removes the last sprintf uses (and the -Wdeprecated-declarations pragmas added in #208 to silence them):

  • test/src/itoa.cpp: replace the sprintf-based itoa/ltoa/utoa/ultoa with a small K&R-style converter supporting any radix 2-36. This also fixes INT_MIN/LONG_MIN negation and makes hex output lowercase, matching avr-libc itoa.
  • api/deprecated-avr-comp/avr/dtostrf.c.impl: use snprintf instead of sprintf. The output length is measured first (snprintf(NULL, 0, ...)) so the bounded call can never truncate, since dtostrf doesn't know the caller's buffer size.
  • api/String.cpp: number constructors and concat() now convert directly into the String's own buffer instead of formatting into a stack buffer and copying it. This also fixes concat(float/double) overflowing its 20-byte stack buffer for large values (e.g. 1e20f produces 24 chars).
    Note: api/IPAddress.cpp already uses snprintf, so no change was needed there.
    All tests pass (972 assertions in 306 test cases).

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clean up use of sprintf

3 participants