Skip to content

Commit

Permalink
Fix length_bytes usize issue
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Mar 28, 2016
1 parent 41f87f8 commit 21cadf4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ macro_rules! length_bytes(
$crate::IResult::Error(a) => $crate::IResult::Error(a),
$crate::IResult::Incomplete(i) => $crate::IResult::Incomplete(i),
$crate::IResult::Done(i1,nb) => {
let nb = nb as usize;
let length_remaining = i1.len();
if length_remaining < nb {
$crate::IResult::Incomplete($crate::Needed::Size(nb - length_remaining))
Expand Down
7 changes: 6 additions & 1 deletion tests/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#[macro_use]
extern crate nom;

use nom::{IResult,Needed,HexDisplay,space,digit};
use nom::{IResult,Needed,HexDisplay,space,digit,be_u16};
use std::str;

#[allow(dead_code)]
Expand Down Expand Up @@ -97,6 +97,11 @@ fn issue_142(){
assert_eq!(subject, expected)
}

#[test]
fn usize_length_bytes_issue(){
length_bytes!(b"012346", be_u16);
}

/*
DOES NOT COMPILE
#[test]
Expand Down

0 comments on commit 21cadf4

Please sign in to comment.