rusty-rain
rusty-rain copied to clipboard
Use of random number generation causes thread panic
Does
Running current version (0.3.6) on Ubuntu 23.04 in terminal
application will cause the following thread panic message:
thread 'main' panicked at 'cannot sample empty range', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.8.4/src/rng.rs:134:9
To repro:
- Open the
terminal
application - Run
rusty-rain
- Resize the window such that the height approaches ~15 characters
-
rusty-rain
will fail at this point, throwing the above panic message
I initially discovered this issue when running codium
and opening a terminal window from within the IDE, which triggers this issue often given the confines of the editor windows.
A quick walk of the code logic suggests that the issue is in pub fn lengths()
in the gen.rs
file. If the height
argument passed into the function equals the hard-coded min range value of 4, then the rnd::rng.gen_range()
function will fail, given that the range provided is now empty (i.e., 4..4).
There's a good discussion of this issue in the Rust project, here: https://github.com/rust-lang/rust/issues/54204.
It's possible that if bounds checks prior to random number generation calls are not made elsewhere in the codebase, similar edge case conditions could trigger this same fault.
Should
Running rusty-rain
in a terminal window should not fail regardless of window dimensions.