about summary refs log tree commit diff
path: root/src/libstd/io/extensions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd/io/extensions.rs')
-rw-r--r--src/libstd/io/extensions.rs48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs
index 07aa25bc044..70bf90eef93 100644
--- a/src/libstd/io/extensions.rs
+++ b/src/libstd/io/extensions.rs
@@ -82,9 +82,9 @@ pub fn u64_to_le_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
     assert!(size <= 8u);
     match size {
       1u => f(&[n as u8]),
-      2u => f(unsafe { transmute::<_, [u8, ..2]>((n as u16).to_le()) }),
-      4u => f(unsafe { transmute::<_, [u8, ..4]>((n as u32).to_le()) }),
-      8u => f(unsafe { transmute::<_, [u8, ..8]>(n.to_le()) }),
+      2u => f(unsafe { & transmute::<_, [u8, ..2]>((n as u16).to_le()) }),
+      4u => f(unsafe { & transmute::<_, [u8, ..4]>((n as u32).to_le()) }),
+      8u => f(unsafe { & transmute::<_, [u8, ..8]>(n.to_le()) }),
       _ => {
 
         let mut bytes = vec!();
@@ -121,9 +121,9 @@ pub fn u64_to_be_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
     assert!(size <= 8u);
     match size {
       1u => f(&[n as u8]),
-      2u => f(unsafe { transmute::<_, [u8, ..2]>((n as u16).to_be()) }),
-      4u => f(unsafe { transmute::<_, [u8, ..4]>((n as u32).to_be()) }),
-      8u => f(unsafe { transmute::<_, [u8, ..8]>(n.to_be()) }),
+      2u => f(unsafe { & transmute::<_, [u8, ..2]>((n as u16).to_be()) }),
+      4u => f(unsafe { & transmute::<_, [u8, ..4]>((n as u32).to_be()) }),
+      8u => f(unsafe { & transmute::<_, [u8, ..8]>(n.to_be()) }),
       _ => {
         let mut bytes = vec!();
         let mut i = size;
@@ -474,26 +474,26 @@ mod test {
         let buf = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09];
 
         // Aligned access
-        assert_eq!(u64_from_be_bytes(buf, 0, 0), 0);
-        assert_eq!(u64_from_be_bytes(buf, 0, 1), 0x01);
-        assert_eq!(u64_from_be_bytes(buf, 0, 2), 0x0102);
-        assert_eq!(u64_from_be_bytes(buf, 0, 3), 0x010203);
-        assert_eq!(u64_from_be_bytes(buf, 0, 4), 0x01020304);
-        assert_eq!(u64_from_be_bytes(buf, 0, 5), 0x0102030405);
-        assert_eq!(u64_from_be_bytes(buf, 0, 6), 0x010203040506);
-        assert_eq!(u64_from_be_bytes(buf, 0, 7), 0x01020304050607);
-        assert_eq!(u64_from_be_bytes(buf, 0, 8), 0x0102030405060708);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 0), 0);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 1), 0x01);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 2), 0x0102);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 3), 0x010203);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 4), 0x01020304);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 5), 0x0102030405);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 6), 0x010203040506);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 7), 0x01020304050607);
+        assert_eq!(u64_from_be_bytes(&buf, 0, 8), 0x0102030405060708);
 
         // Unaligned access
-        assert_eq!(u64_from_be_bytes(buf, 1, 0), 0);
-        assert_eq!(u64_from_be_bytes(buf, 1, 1), 0x02);
-        assert_eq!(u64_from_be_bytes(buf, 1, 2), 0x0203);
-        assert_eq!(u64_from_be_bytes(buf, 1, 3), 0x020304);
-        assert_eq!(u64_from_be_bytes(buf, 1, 4), 0x02030405);
-        assert_eq!(u64_from_be_bytes(buf, 1, 5), 0x0203040506);
-        assert_eq!(u64_from_be_bytes(buf, 1, 6), 0x020304050607);
-        assert_eq!(u64_from_be_bytes(buf, 1, 7), 0x02030405060708);
-        assert_eq!(u64_from_be_bytes(buf, 1, 8), 0x0203040506070809);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 0), 0);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 1), 0x02);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 2), 0x0203);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 3), 0x020304);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 4), 0x02030405);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 5), 0x0203040506);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 6), 0x020304050607);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 7), 0x02030405060708);
+        assert_eq!(u64_from_be_bytes(&buf, 1, 8), 0x0203040506070809);
     }
 }