Repository navigation
Conversation
newlib was configured without --enable-newlib-io-c99-formats, so its printf family does not understand the z, t and j length modifiers. A conversion such as %zu is skipped without consuming its argument, so every following argument is read from the wrong slot, and a later %s dereferences an integer. mpv and FFmpeg use %zd/%zu in log messages, and this crashed Switchfin on the Vita (dragonflylee/switchfin#291).
devnoname120
approved these changes
Nov 23, 2026
devnoname120
left a comment
Member
There was a problem hiding this comment.
No blocking findings. I verified the exact head 9a826a1 against base 38d1e45 rather than relying only on the configure-option documentation.
Evidence:
- Rebuilt the pinned newlib (
2e428297) with the base and PR configure arguments. The PR build defines_WANT_IO_C99_FORMATS=1; the base does not. The option reaches the target configuration and preserves the existing long-long support. - Linked representative
snprintfandsscanfprograms through the normal Vita compiler driver against each rebuilt libc, then executed the ARM code under a Cortex-A9 emulator with the Vita TLS import stubbed. The base formatter emits the unsupported modifiers literally (zu td j) and then faults on the shifted%sargument; the PR build produces123 -45 6789012345 ok. The base scanner performs zero assignments; the PR build parses all threez/t/jvalues correctly. - Checked the target type mapping used by newlib's dispatch:
size_tisunsigned int,ptrdiff_tisint, andintmax_tislong long, matching the implementation paths selected by this flag. - Rebuilt with both hard-float and softfp Vita compilers. Both configurations complete, and the softfp objects retain the softfp calling convention.
- Inspected the PR-produced stage-1 artifact: its provenance matches the PR lock, installed
newlib.hdefines the feature macro,<inttypes.h>exposes the correspondingSCN*macros, and a normal-driver link selects the artifact's C99-enabled libc. - The representative linked text increase was about 2.1 KiB for
snprintfand 5.8 KiB forsscanf, with no data/BSS increase.
Two non-blocking follow-ups:
- Add a direct toolchain-contract assertion for
_WANT_IO_C99_FORMATS(and preferably one 8-bitSCN*macro). The full build proves the option is accepted, but without a focused assertion a later recipe change could silently drop this behavior. - The PR description's “No API change” wording is slightly too broad: enabling the option intentionally exposes fifteen 8-bit
SCN*macros from<inttypes.h>. This is a compatible API addition, and there is still no ABI or function-signature change.
The remaining downstream CI jobs are still running, but the implementation and produced stage-1 SDK are sufficiently verified for approval.
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.
What does this change?
Adds
--enable-newlib-io-c99-formatsto newlib's configure flags incmake/recipes/BuildSdkComponents.cmake, so the printf/scanf family supports the C99 length modifiersz(size_t),t(ptrdiff_t) andj(intmax_t).Why is this change needed?
newlib was configured without
--enable-newlib-io-c99-formats, so its printf family does not understand thez,tandjlength modifiers. A conversion such as%zuis skipped without consuming its argument: the modifier is printed as a literal character, every following argument is read from the wrong slot, and a later%sdereferences an integer.mpv and FFmpeg use
%zd/%zuin log messages, and this crashed Switchfin on the Vita (dragonflylee/switchfin#291). The crash came after a seek, while mpv formatted"%s/%d: %zd packets, %zd bytes%s%s\n".Minimal repro:
Testing
z/t/jbefore calling newlib (fix(psv): support C99 printf length modifiers dragonflylee/switchfin#291) stopped the crash.libc/stdio/vfprintf.c,case 'j',case 'z'andcase 't'sit behind#ifdef _WANT_IO_C99_FORMATS, which this flag defines.Compatibility
%z…,%t…and%j…conversions now format and consume their argument as C99 requires, instead of printing the modifier and leaving the argument for the next conversion. Code that worked around the old behavior by avoiding these modifiers is unaffected.long longsupport (--enable-newlib-io-long-long) is already enabled, sojmaps onto existing 64-bit handling.Third-party material
None
AI assistance
Additional context
newlib/configure.ac("enable C99 support in IO functions like printf/scanf").