File tree 1 file changed +8
-1
lines changed
1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -79,12 +79,19 @@ impl Observable for u64 {
79
79
}
80
80
}
81
81
82
+ /// Fill dest from src
83
+ ///
84
+ /// Returns `(n, byte_len)`. `src[..n]` is consumed (and possibly mutated),
85
+ /// `dest[..byte_len]` is filled. `src[n..]` and `dest[byte_len..]` are left
86
+ /// unaltered.
82
87
fn fill_via_chunks < T : Observable > ( src : & mut [ T ] , dest : & mut [ u8 ] ) -> ( usize , usize ) {
83
88
let size = core:: mem:: size_of :: < T > ( ) ;
84
89
let byte_len = min ( src. len ( ) * size, dest. len ( ) ) ;
85
90
let num_chunks = ( byte_len + size - 1 ) / size;
86
91
87
- // Byte-swap for portability of results:
92
+ // Byte-swap for portability of results. This must happen before copying
93
+ // since the size of dest is not guaranteed to be a multiple of T or to be
94
+ // sufficiently aligned.
88
95
if cfg ! ( target_endian = "big" ) {
89
96
for x in & mut src[ ..num_chunks] {
90
97
* x = x. to_le ( ) ;
You can’t perform that action at this time.
0 commit comments