[all-commits] [llvm/llvm-project] 98fb5d: [libc] Fix EOF handling in fscanf (#211982)
Alexey Samsonov via All-commits
all-commits at lists.llvm.org
Tue Jul 28 08:27:29 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 98fb5dae73c3887e6659ee126b131b004d12592d
https://github.com/llvm/llvm-project/commit/98fb5dae73c3887e6659ee126b131b004d12592d
Author: Alexey Samsonov <vonosmas at gmail.com>
Date: 2026-07-28 (Tue, 28 Jul 2026)
Changed paths:
M libc/src/stdio/scanf_core/CMakeLists.txt
M libc/src/stdio/scanf_core/vfscanf_internal.h
M libc/test/src/stdio/CMakeLists.txt
M libc/test/src/stdio/fscanf_test.cpp
Log Message:
-----------
[libc] Fix EOF handling in fscanf (#211982)
`fscanf` family of functions should return EOF if:
- end of input is reached before either the first successful conversion
or a matching failure occurs;
- a read error occurs.
This wasn't handled correctly before - in "system FILE" mode (in overlay
build) `EOF` return value from `getc` was passed through to parser,
violating `Reader` interface, which triggered infinite loops on
"while-not-EOF" `fscanf` loops. In llvm-libc-FILE mode `fscanf` simply
returned zero instead of EOF, because the code only checked error
indicator on a stream.
This PR removes _any_ lookups of eof/error indicators on an input stream
- instead we can simply rely on the `getc` (system or internal) function
behavior, which returns `EOF` on unsuccessful reads.
Extend the test cases for `fscanf` to cover various return values in
cases when `EOF` is reached (before or after conversions / matching
errors).
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list