Skip to content

Commit

Permalink
Parse empty docblock lines for backtraces without panicking
Browse files Browse the repository at this point in the history
Fixes #263.
  • Loading branch information
csnover committed Jun 7, 2024
1 parent 4f4c690 commit 8b5de15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions binrw/tests/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion binrw_derive/src/binrw/backtrace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8b5de15

Please sign in to comment.