Avoid exceptions in UCI spin option validation - #6738
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
ef75adc to
463afd4
Compare
463afd4 to
26e9cb7
Compare
|
clang-format 20 needs to be run on this PR. (execution 24610608033 / attempt 1) |
|
This one doesn't need a fishtest run (it doesn't affect the engine's play) |
|
we avoided charconv because in the past workers on fishtest failed because it's missing |
|
I recall this as well, but I do not longer recall which environment / compiler version was involved. For gcc, full support of charconv seems to be only available from 11+ and clang even a bit later. In CI our current set of supported compiler see to work fine, at least for the smoke test. We're a bit on the same path as with the fens. In principle we rely on the gui to provide valid input. |
|
iirc it was clang 13 from sebs machine and he had a somewhat special system where it was missing.. |
Malformed spin-option values are validated in Option::operator=, but using std::stoi for that check can throw std::invalid_argument or std::out_of_range. Because Stockfish is built with -fno-exceptions, malformed setoption input terminates the engine. Use std::strtol for spin-option validation instead. This keeps the validation path non-throwing without depending on std::from_chars support across older toolchains. Reject values when: - no conversion happens - trailing garbage remains - conversion overflows - result falls outside [min, max] Bench: 2984258
26e9cb7 to
74f97d0
Compare
|
Addressed the charconv concern by switching the validation path from std::from_chars to std::strtol in the latest force-push. This keeps the fix non-throwing in -fno-exceptions builds without depending on charconv support on older toolchains. Bench is still unchanged at 2984258. |
|
i'd also prefer if we simply clamp the value if it is outside the range |
Summary
Malformed
setoptioninput for aspinoption is validated inOption::operator=, but usingstd::stoifor that check can throwstd::invalid_argumentorstd::out_of_range. Because Stockfish is compiled with-fno-exceptions, malformed console input terminates the engine.Examples on current master:
Confirmed live on
stockfish-dev-20260415-b1fb50ae:Fix
Replace the throwing validation path in
Option::operator=withstd::strtol. This keeps validation non-throwing without depending onstd::from_charsavailability on older toolchains. Rejected values return early without mutating the option.The new validation rejects:
[min, max]Testing
Malformed values are now rejected without terminating the engine.