Repository navigation
Conversation
Add printf_test() to the libc tests of ostest. It checks that printf() takes each argument at its right size for %a, %L and %n, that an unknown conversion takes no argument and ends the conversions, that it reads no further than the end of the format, that a width above 255 gives the right length, that output above INT_MAX fails with EOVERFLOW, and that numbered arguments stay in order. Each format goes through a function with no format attribute, because a compiler warns about some of them. An error prints the format and stops with an assertion. The test adapts to CONFIG_LIBC_FLOATINGPOINT and CONFIG_LIBC_NUMBERED_ARGS. Option TESTING_OSTEST_PRINTF selects the test, and it is on unless DEFAULT_SMALL is set, so small boards do not grow. Part of apache/nuttx#21467 Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
casaroli
force-pushed
the
apps-printf-safety-test-up
branch
from
November 5, 2026 08:18
11cc571 to
f31f43e
Compare
xiaoxiang781216
approved these changes
Nov 5, 2026
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.
depends-on: apache/nuttx/pull/21474
Summary
A test of
printf()for apache/nuttx#21474. Part of apache/nuttx#21467.printf_test()runs with the libc tests of ostest. It checks that:%a,%Land%ntake each argument at its right sizeprintf()reads no further than the end of the formatINT_MAXfails withEOVERFLOWThe test adapts to
CONFIG_LIBC_FLOATINGPOINTandCONFIG_LIBC_NUMBERED_ARGS. An error prints the format and stops with an assertion.Impact
A new file in ostest and the option
CONFIG_TESTING_OSTEST_PRINTF. It is on unlessDEFAULT_SMALLis set, so small boards do not grow. No change to any other code.This test fails on NuttX master until apache/nuttx#21474 merges, so this PR must merge after it.
Testing
ostest with Make, NuttX flat builds under QEMU:
rv-virt:nsh, float offrv-virt:nsh, float offrv-virt:nsh, float and numbered arguments onqemu-armv8a:nsh, float and numbered arguments onThe failure on master:
These runs used f4044a05e50 of #21474.
tools/checkpatch.sh -c -u -m -gpasses.