Skip to content

Commit

Permalink
Fix integer underflow in extra_offset
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusklaas committed Jun 10, 2016
1 parent 931e71e commit 88fdf9a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/utils.rs
Expand Up @@ -23,11 +23,10 @@ use rewrite::{Rewrite, RewriteContext};
use SKIP_ANNOTATION;

// Computes the length of a string's last line, minus offset.
#[inline]
pub fn extra_offset(text: &str, offset: Indent) -> usize {
match text.rfind('\n') {
// 1 for newline character
Some(idx) => text.len() - idx - 1 - offset.width(),
Some(idx) => text.len().checked_sub(idx + 1 + offset.width()).unwrap_or(0),
None => text.len(),
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/target/issue-1055.rs
@@ -0,0 +1,4 @@
fn issue_1055() {
let foo = (|| {
})();
}

0 comments on commit 88fdf9a

Please sign in to comment.