3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-08-02 12:13:25 +00:00
z3/src
Copilot 1c8b6cfdb8
scanner: emit ERROR_TOKEN on I/O failure instead of silent EOF (#10294)
`scanner::scan()` was returning `EOF_TOKEN` when the underlying stream
had `badbit` set, making a failed read (EIO, ENOSPC, etc.)
indistinguishable from a clean end-of-file. Z3 would silently produce no
output with exit code 0.

## Root cause

`std::istream::gcount()` returns 0 for both normal EOF and I/O failure.
`read_char()` returned -1 in both cases, and `scan()`'s `-1` handler
unconditionally set `EOF_TOKEN`.

## Fix

### `src/parsers/util/scanner.cpp`
Check `m_stream.bad()` in the `-1` case; emit an error message and
`ERROR_TOKEN` on failure:

```cpp
case static_cast<char>(-1):
    if (m_stream.bad()) {
        m_err << "ERROR: I/O failure while reading input stream.\n";
        m_state = ERROR_TOKEN;
    } else {
        m_state = EOF_TOKEN;
    }
    break;
```

### `src/test/scanner_io.cpp` (new)
Regression test (ported from the `io_test` branch) verifying:
1. A good stream scans to completion (`n > 0` tokens).
2. A stream with `badbit` pre-set produces `ERROR_TOKEN` or a non-empty
error message rather than silent EOF.

### `src/test/main.cpp` + `src/test/CMakeLists.txt`
Register `tst_scanner_io` in the `FOR_EACH_ALL_TEST` macro and add
`scanner_io.cpp` to the build.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
Co-authored-by: Nikolaj Bjorner <nikolaj@cs.stanford.edu>
2026-07-29 14:00:42 -07:00
..
ackermannization block ackermann over nested selects 2026-06-19 10:41:56 -07:00
api Fix build-pyodide: correct z3test.py path in cibuildwheel test-command (#10263) 2026-07-27 18:48:36 -07:00
ast Make implicit switch case fall-throughs explicit (#10284) 2026-07-29 09:05:42 -07:00
cmd_context Use macros to disable semi-colon warnings for blocks of macros. (#10192) 2026-07-22 18:01:50 -07:00
math Fstar opt2 (#10261) 2026-07-29 09:12:56 -07:00
model updates to tptp_frontend 2026-07-04 14:34:21 -07:00
muz Make implicit switch case fall-throughs explicit (#10284) 2026-07-29 09:05:42 -07:00
nlsat Remove unnecessary semicolons (Attempt 2) (#10020) 2026-07-02 12:47:29 -07:00
opt Make implicit switch case fall-throughs explicit (#10284) 2026-07-29 09:05:42 -07:00
params Fstar opt2 (#10261) 2026-07-29 09:12:56 -07:00
parsers scanner: emit ERROR_TOKEN on I/O failure instead of silent EOF (#10294) 2026-07-29 14:00:42 -07:00
qe Simplify has_array_var_in_index in qe_mbp.cpp (#10289) 2026-07-29 09:07:17 -07:00
sat Make implicit switch case fall-throughs explicit (#10284) 2026-07-29 09:05:42 -07:00
shell Fixes necessary to compile z3 included in clang-tidy via FetchContents. (#9768) 2026-06-08 19:44:01 -07:00
smt Make implicit switch case fall-throughs explicit (#10284) 2026-07-29 09:05:42 -07:00
solver fix: parallel mode exits unknown immediately for QF_BV due to reason-string mismatch (#10183) 2026-07-21 19:48:55 -07:00
tactic Make implicit switch case fall-throughs explicit (#10284) 2026-07-29 09:05:42 -07:00
test scanner: emit ERROR_TOKEN on I/O failure instead of silent EOF (#10294) 2026-07-29 14:00:42 -07:00
util Fix releaseClang segfault: declare invoke_exit_action [[noreturn]], remove __builtin_unreachable() from UNREACHABLE() (#10295) 2026-07-29 13:23:43 -07:00
CMakeLists.txt git bindings v1.0 2026-02-18 21:02:25 -08:00