Skip to content

Commit

Permalink
fat: Don't reference packed fields
Browse files Browse the repository at this point in the history
This is undefined behaviour:
rust-lang/rust#46043

Fixes: #70

Signed-off-by: Rob Bradford <[email protected]>
  • Loading branch information
rbradford committed Oct 27, 2020
1 parent 3420f2f commit a04fa80
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/fat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,18 @@ impl<'a> Directory<'a> {
let lfn_seq = ((lfns[i].seq & 0x1f) as usize) - 1;
let lfn_block = &mut long_entry[lfn_seq * 13..(lfn_seq + 1) * 13];

// Need explicit copy to avoid borrowing packed structure
let name = lfns[i].name;
let s = &mut lfn_block[0..5];
s.copy_from_slice(unsafe { &lfns[i].name[..] });
s.copy_from_slice(&name);

let name2 = lfns[i].name2;
let s = &mut lfn_block[5..11];
s.copy_from_slice(unsafe { &lfns[i].name2[..] });
s.copy_from_slice(&name2);

let name3 = lfns[i].name3;
let s = &mut lfn_block[11..13];
s.copy_from_slice(unsafe { &lfns[i].name3[..] });
s.copy_from_slice(&name3);

continue;
}
Expand Down

0 comments on commit a04fa80

Please sign in to comment.