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 Jan 4, 2021
1 parent 59a20b3 commit 2eb83f3
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/optimal_fit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ const HYPHEN_PENALTY: usize = 25;
/// 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).
///
/// **Note:** Only available when the `smawk` Cargo feature is
/// enabled.
pub fn wrap_optimal_fit<'a, T: Fragment, F: Fn(usize) -> usize>(
Expand Down

0 comments on commit 2eb83f3

Please sign in to comment.