Subtract with overflow when first line is empty
nthuemmel-scontain opened this issue · 0 comments
nthuemmel-scontain commented
Given the following simple test program:
use std::fs::File;
fn main() {
let mut reader = easy_reader::EasyReader::new(File::open("test.txt").unwrap()).unwrap();
reader.eof();
while let Some(line) = reader.prev_line().unwrap() {
println!("{}", line);
}
}
with the following test file test.txt
:
Blank line above!
(Notice that the first line is blank!)
The program panics in debug mode with a substraction overflow error:
thread 'main' panicked at 'attempt to subtract with overflow', ~/.cargo/registry/src/github.com-1ecc6299db9ec823/easy_reader-0.5.1/src/lib.rs:392:57
stack backtrace:
0: rust_begin_unwind
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:517:5
1: core::panicking::panic_fmt
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:100:14
2: core::panicking::panic
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:50:5
3: easy_reader::EasyReader<R>::find_end_line
at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/easy_reader-0.5.1/src/lib.rs:392:57
4: easy_reader::EasyReader<R>::read_line
at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/easy_reader-0.5.1/src/lib.rs:258:44
5: easy_reader::EasyReader<R>::prev_line
at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/easy_reader-0.5.1/src/lib.rs:179:9
6: easy_reader_empty_start_line::main
at ./src/main.rs:7:28
7: core::ops::function::FnOnce::call_once
at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/ops/function.rs:227:5
(In release mode, it will panic with thread 'main' panicked at 'called
Result::unwrap()on an
Err value: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }'
since overflow checks are disabled)
Tested with easy_reader 0.5.1