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

Panic from print_text #22

Closed
samtay opened this issue Jul 12, 2020 · 3 comments
Closed

Panic from print_text #22

samtay opened this issue Jul 12, 2020 · 3 comments

Comments

@samtay
Copy link

samtay commented Jul 12, 2020

Someone has observed thread 'main' panicked at 'attempt to subtract with overflow' coming from a skin.print_text call (ref samtay/so#8), and also found that such panic goes away when using skin.print_inline. Unfortunately I couldn't repo this myself, but the relevant details from that issue are:

  • OS: Ubuntu 18.04
  • Terminal: gnome-terminal
  • Terminal size when rendering: (190, 51)
  • Relevant part of the stack trace:
      13:     0x55f43543f6ed - core::panicking::panic::h68e56c2eeba99c8c
                                 at src/libcore/panicking.rs:50
    14:     0x55f434c96c0d - minimad::compound::Compound::cut_tail::h65a621fcce14ec17
                                 at /home/e/.cargo/registry/src/github.com-1ecc6299db9ec823/minimad-0.6.4/src/compound.rs:117
    15:     0x55f434c7062c - termimad::wrap::hard_wrap_composite::ha144c51dfb0493a2
                                 at /home/eyehuda/.cargo/registry/src/github.com-1ecc6299db9ec823/termimad-0.8.24/src/wrap.rs:137
    16:     0x55f434c71116 - termimad::wrap::hard_wrap_lines::hcc2fff69ff958a06
                                 at /home/eyehuda/.cargo/registry/src/github.com-1ecc6299db9ec823/termimad-0.8.24/src/wrap.rs:172
    17:     0x55f434c72f2e - termimad::text::FmtText::from_text::hdd93418c5a6ceb6b
                                 at /home/eyehuda/.cargo/registry/src/github.com-1ecc6299db9ec823/termimad-0.8.24/src/text.rs:44
    18:     0x55f434c72de0 - termimad::text::FmtText::from::h5006d4ececb9711c
                                 at /home/eyehuda/.cargo/registry/src/github.com-1ecc6299db9ec823/termimad-0.8.24/src/text.rs:32
    19:     0x55f434c7f0eb - termimad::skin::MadSkin::term_text::hd65d68486384d1a9
                                 at /home/eyehuda/.cargo/registry/src/github.com-1ecc6299db9ec823/termimad-0.8.24/src/skin.rs:208
    20:     0x55f434c7f160 - termimad::skin::MadSkin::print_text::h1276bb441ef97417
                                 at /home/eyehuda/.cargo/registry/src/github.com-1ecc6299db9ec823/termimad-0.8.24/src/skin.rs:243
    
  • Input causing panic: gist link

Note the markdown input is quite large, so I put it in a gist. I also embedded it within the ./examples/text/main.rs file so that it would be easier to run.

EDIT: I was able to repro this. At terminal width 112 there is no panic. If the terminal width is greater than or equal to 117, you can observe this panic.

I think if you make sure your terminal width is that wide (e.g. go full screen), and run this:

cd /path/to/termimad
curl -o "examples/text/main.rs" "https://gist.githubusercontent.com/samtay/cf9d1b8c0c7935baf6f6971101bd567e/raw/dff5e762f9a56f76aa64e9c61b57311c42c7a0f0/example-panic.rs"
RUST_BACKTRACE=1 cargo run --example text

you should be able to observe it.

@Canop
Copy link
Owner

Canop commented Jul 13, 2020

I do reproduce it.

Smaller example:

use std::io::Write;
use termimad::*;

static MD: &str = r#"
Note that the "before" code is basically the [implementation of today's `poll_fn` function](https://github.com/rust-lang-nursery/futures-rs/blob/0.3.1/futures-util/src/future/poll_fn.rs#L48-L56)
"#;

fn main() {
    let skin = MadSkin::default();
    skin.print_text(MD);
}

@Canop
Copy link
Owner

Canop commented Jul 13, 2020

This should have been fixed. Can you please confirm it's OK @samtay ?

@samtay
Copy link
Author

samtay commented Jul 13, 2020

Yes, I just tried out master and it's working on my end. Thanks for such a quick fix!

@samtay samtay closed this as completed Jul 13, 2020
lerina pushed a commit to lerina/termimad that referenced this issue Jan 14, 2022
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

No branches or pull requests

2 participants