ucrt: fgets with room for only the NUL returns an empty string #63
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!63
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/63/head"
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?
@Repla09 on GitHub · 2026-11-26 12:13 UTC · original
Repla09:fix/ucrt-fgets-one-byte-buffer→main· +28 −3 · 1 files · 2 commits · merged 2026-11-26 12:48 UTCfgets(buf, 1, f)has room only for the terminator, so it reads nothing. Since no end of file was met, C (7.21.7.2) has it store""and returnbuf; the host libc does the same (a C check on macOS printsret=buf b0=0 next=a). The host returned NULL whenever no character was read.Now it returns NULL only when an end of file or error ends the read before any character.
fgets_with_room_for_only_the_nul_stores_an_empty_stringfails on main. It checks thatn = 1stores"", returns the buffer, consumes nothing and sets no end of file, and that an end of file before any character still returns NULL.Testing
cargo test --target x86_64-apple-darwin -p victory-hlepasses (222 unit, 15 native_probe; the D3D12 probe test skipped, no Metal Shader Converter here).x86_64-apple-darwinshows no new warnings;rustfmt --checkandcargo xtask policypass.@LakshanSivakumar on GitHub · 2026-11-26 12:45 UTC · original · approved these changes
Looks good: n<=0 still gives EINVAL and NULL, n==1 stores an empty string without reading, and EOF/error paths are unchanged, matching C 7.21.7.2 and UCRT. The test fails on main. Approved.