diff --git a/0001-Fix-prop_ext_-u-int_-native_endian-on-BE-targets.patch b/0001-Fix-prop_ext_-u-int_-native_endian-on-BE-targets.patch new file mode 100644 index 0000000..c26da66 --- /dev/null +++ b/0001-Fix-prop_ext_-u-int_-native_endian-on-BE-targets.patch @@ -0,0 +1,52 @@ +From 403638e8d7ca2b0cd24034976c7a164bbd15b4dd Mon Sep 17 00:00:00 2001 +From: Josh Stone +Date: Mon, 13 Nov 2017 11:26:47 -0800 +Subject: [PATCH] Fix prop_ext_[u]int_*::native_endian on BE targets + +The similar `big_endian` tests were using an offset to read from the +end of the written `u64`, but the `native_endian` tests were reading +directly, just like the `little_endian` tests. That's of course only +correct when the target actually is little endian. + +That `big_endian` offset is now sliced directly, instead of cloning into +another vector, and then this logic is also used in the `native_endian` +test, depending on the current `#[cfg(target_endian)]`. + +Fixes #102. +--- + src/lib.rs | 12 ++++++++---- + 1 file changed, 8 insertions(+), 4 deletions(-) + +diff --git a/src/lib.rs b/src/lib.rs +index b60fe7c..35c0069 100644 +--- a/src/lib.rs ++++ b/src/lib.rs +@@ -2865,9 +2865,8 @@ mod stdtests { + fn prop(n: $ty_int) -> bool { + let mut wtr = vec![]; + wtr.$write::(n.clone()).unwrap(); +- let mut rdr = Vec::new(); +- rdr.extend(wtr[wtr.len()-$bytes..].iter().map(|&x| x)); +- let mut rdr = Cursor::new(rdr); ++ let offset = wtr.len() - $bytes; ++ let mut rdr = Cursor::new(&mut wtr[offset..]); + n == rdr.$read::($bytes).unwrap() + } + qc_sized(prop as fn($ty_int) -> bool, $max); +@@ -2889,7 +2888,12 @@ mod stdtests { + fn prop(n: $ty_int) -> bool { + let mut wtr = vec![]; + wtr.$write::(n.clone()).unwrap(); +- let mut rdr = Cursor::new(wtr); ++ let offset = if cfg!(target_endian = "big") { ++ wtr.len() - $bytes ++ } else { ++ 0 ++ }; ++ let mut rdr = Cursor::new(&mut wtr[offset..]); + n == rdr.$read::($bytes).unwrap() + } + qc_sized(prop as fn($ty_int) -> bool, $max); +-- +2.15.0 + diff --git a/rust-byteorder.spec b/rust-byteorder.spec index 3c81255..7c1e1b9 100644 --- a/rust-byteorder.spec +++ b/rust-byteorder.spec @@ -12,6 +12,8 @@ Summary: Library for reading/writing numbers in big-endian and little-end License: Unlicense or MIT URL: https://crates.io/crates/byteorder Source0: https://crates.io/api/v1/crates/%{crate}/%{version}/download#/%{crate}-%{version}.crate +# https://github.com/BurntSushi/byteorder/pull/104 +Patch0: 0001-Fix-prop_ext_-u-int_-native_endian-on-BE-targets.patch ExclusiveArch: %{rust_arches}