Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subtract with overflow when first line is empty #10

Closed
nthuemmel-scontain opened this issue Jan 27, 2022 · 0 comments · Fixed by #11
Closed

Subtract with overflow when first line is empty #10

nthuemmel-scontain opened this issue Jan 27, 2022 · 0 comments · Fixed by #11

Comments

@nthuemmel-scontain
Copy link

nthuemmel-scontain commented Jan 27, 2022

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 anErr value: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }' since overflow checks are disabled)

Tested with easy_reader 0.5.1

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 a pull request may close this issue.

1 participant