diff --git a/binrw/tests/error.rs b/binrw/tests/error.rs index 6c420311..c860b541 100644 --- a/binrw/tests/error.rs +++ b/binrw/tests/error.rs @@ -293,6 +293,18 @@ fn no_seek_unit_enum() { } } +#[test] +fn parse_backtrace_with_empty_comment_lines() { + #[derive(binrw::BinRead)] + pub struct Test { + /// Blank next line has no whitespace… + + /// …but it is part of the same span, and needs to not crash the + /// backtrace formatter + _a: u32, + } +} + #[test] fn show_backtrace() { use alloc::borrow::Cow; diff --git a/binrw_derive/src/binrw/backtrace/mod.rs b/binrw_derive/src/binrw/backtrace/mod.rs index 552d84bf..425378ae 100644 --- a/binrw_derive/src/binrw/backtrace/mod.rs +++ b/binrw_derive/src/binrw/backtrace/mod.rs @@ -52,7 +52,7 @@ impl BacktraceFrame { format!("{}{}", " ".repeat(spaces_to_add), line) } } else { - line[min_whitespace..].to_owned() + line.get(min_whitespace..).unwrap_or_default().to_owned() }; (min_whitespace + 1, line)