Skip to content

Commit

Permalink
Document that wrap_optimal_fit panics
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeisler committed Dec 28, 2020
1 parent bba043c commit d9ebda2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fuzz/fuzz_targets/wrap_optimal_fit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ fuzz_target!(|input: (Vec<BoxGluePenalty>, u64)| {
.and_then(|sum| sum.checked_add(f.penalty_width()))
});
if total_width.is_none() {
// The total width overflows usize — this is not supported so
// return here to avoid a crash.
return;
}

Expand Down
5 changes: 5 additions & 0 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,11 @@ const HYPHEN_PENALTY: usize = 25;
/// by Knuth and Plass. The implementation here is based on [Python
/// code by David
/// Eppstein](https://github.com/jfinkels/PADS/blob/master/pads/wrap.py).
///
/// # Panics
///
/// The total width of all fragments must fit inside an `usize`
/// (including the whitespace and penalty widths).
pub fn wrap_optimal_fit<'a, T: Fragment, F: Fn(usize) -> usize>(
fragments: &'a [T],
line_widths: F,
Expand Down

0 comments on commit d9ebda2

Please sign in to comment.