Skip to content

Commit

Permalink
really test decode_varint_slow instead of passing it slices that have…
Browse files Browse the repository at this point in the history
… already been emptied
  • Loading branch information
mumbleskates committed Feb 2, 2024
1 parent 63c0024 commit b9df2ec
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,7 @@ mod test {

#[test]
fn varint() {
fn check(value: u64, mut encoded: &[u8]) {
fn check(value: u64, encoded: &[u8]) {
// Small buffer.
let mut buf = Vec::with_capacity(1);
encode_varint(value, &mut buf);
Expand All @@ -1615,11 +1615,10 @@ mod test {

assert_eq!(encoded_len_varint(value), encoded.len());

let roundtrip_value =
decode_varint(&mut <&[u8]>::clone(&encoded)).expect("decoding failed");
let roundtrip_value = decode_varint(&mut &*encoded).expect("decoding failed");
assert_eq!(value, roundtrip_value);

let roundtrip_value = decode_varint_slow(&mut encoded).expect("slow decoding failed");
let roundtrip_value = decode_varint_slow(&mut &*encoded).expect("slow decoding failed");
assert_eq!(value, roundtrip_value);
}

Expand Down Expand Up @@ -1680,11 +1679,10 @@ mod test {

#[test]
fn varint_overflow() {
let mut u64_max_plus_one: &[u8] =
&[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x02];
let u64_max_plus_one: &[u8] = &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x02];

decode_varint(&mut u64_max_plus_one).expect_err("decoding u64::MAX + 1 succeeded");
decode_varint_slow(&mut u64_max_plus_one)
decode_varint(&mut &*u64_max_plus_one).expect_err("decoding u64::MAX + 1 succeeded");
decode_varint_slow(&mut &*u64_max_plus_one)
.expect_err("slow decoding u64::MAX + 1 succeeded");
}

Expand Down

0 comments on commit b9df2ec

Please sign in to comment.