Skip to content

Fix panic on --runs 0 - #923

Open
VXNCXNX wants to merge 1 commit into
sharkdp:masterfrom
VXNCXNX:fix/zero-runs-panic
Open

Fix panic on --runs 0#923
VXNCXNX wants to merge 1 commit into
sharkdp:masterfrom
VXNCXNX:fix/zero-runs-panic

Conversation

@VXNCXNX

@VXNCXNX VXNCXNX commented Aug 17, 2026

Copy link
Copy Markdown

What's broken

--runs 0 and --max-runs 0 panic with an arithmetic overflow instead of reporting the bad value. --min-runs 0 panics too, for any command slower than the minimum benchmarking time.

Repro

$ hyperfine --runs 0 'true'
Benchmark 1: true
thread 'main' panicked at src/benchmark/mod.rs:277:31:
attempt to subtract with overflow

Exit code is 101. It is easy to hit from a script where the run count comes from a variable.

The fix

Benchmark::run computes count - 1 after the initial timing run, so a count of zero underflows. An explicit maximum of zero is rejected in Options::from_cli_arguments, since asking for at most zero runs cannot be satisfied. A zero minimum is treated as valid and clamped to 1 instead of rejected: no lower bound is a coherent request, and the initial run has already happened by then. Happy to reject --min-runs 0 as well if you would rather have it symmetric.

Verification

$ hyperfine --runs 0 'true'
Error: At least one run has to be performed. Please specify a value larger than zero for '--runs'
$ hyperfine --debug-mode --min-runs 0 'sleep 4'
Benchmark 1: sleep 4
  Time (abs ≡):         4.000 s   [User: 0.000 s, System: 0.000 s]

Two tests added in tests/integration_tests.rs. Full suite passes (44 / 19 / 41), cargo fmt --check clean.


Disclosure: this patch was written with the help of Claude (an LLM). I reviewed the diff, ran the test suite, and verified the behaviour against a real build before opening this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant