ucrt: follow the CRT's buffer rules for legacy and ISO vsprintf #70
No reviewers
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS!70
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-70"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Olima34 on GitHub · 2026-11-26 13:41 UTC · original
Olima34:fix/ucrt-vsprintf-buffer-rules→main· +59 −22 · 2 files · 2 commits · merged 2026-11-26 15:41 UTCWhat this changes
__stdio_common_vs(w)printfhad its two non-standard buffer modes swapped, and the sizing idiom failed outside the standard one. Per Microsoft's_vsnprintfreference and the CRT headers' choice of options (_vsnwprintf_lpassesLEGACY_VSPRINTF_NULL_TERMINATION,_vswprintf_c_l, behind ISOvswprintf, passes none):_vsnprintf(legacy)vswprintf(no option)len(was: NUL, -1)len)countchars, no NUL, -1 (was: NUL)buffer == NULL,count == 0So
swprintf(buf, 4, L"%d", 1234)no longer leavesbufunterminated, and_vsnprintf(NULL, 0, fmt, ...)returns the size to allocate. A null buffer with room isEINVAL. The standard (snprintf) mode is unchanged.The existing test encoded the swapped behaviour; it is replaced by
legacy_and_iso_printf_truncate_as_the_ucrt_does, which covers each mode and case, narrow and wide.How it was tested
cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory(all pass, native probe tests included)cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings, also with--all-features; clippy forx86_64-apple-darwinreports nothing in the files touched (host_posixis not built for Windows)cargo test --workspaceandcargo xtask policymainand passes with the changeChecklist
VICTORY_*variable and documented (none added)@LakshanSivakumar on GitHub · 2026-11-26 14:55 UTC · original · approved these changes
The legacy and ISO vsprintf buffer modes now match UCRT, including EINVAL for a NULL buffer with count > 0. Thanks.