diff options
| author | Aaron Turon <aturon@mozilla.com> | 2014-05-14 14:39:16 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-05-15 13:50:33 -0700 |
| commit | 912a9675c0b7f9e8c836983e525b180c48693925 (patch) | |
| tree | 3543072ddff4c87068ed5b191db6b57660662fb7 /src/libnative | |
| parent | d547de998d33e5b688533f4159ea997c940d9431 (diff) | |
Make `from_bits` in `bitflags!` safe; add `from_bits_truncate`
Previously, the `from_bits` function in the `std::bitflags::bitflags` macro was marked as unsafe, as it did not check that the bits being converted actually corresponded to flags. This patch changes the function to check against the full set of possible flags and return an `Option` which is `None` if a non-flag bit is set. It also adds a `from_bits_truncate` function which simply zeros any bits not corresponding to a flag. This addresses the concern raised in https://github.com/mozilla/rust/pull/13897
Diffstat (limited to 'src/libnative')
| -rw-r--r-- | src/libnative/io/file_unix.rs | 4 | ||||
| -rw-r--r-- | src/libnative/io/file_win32.rs | 4 |
2 files changed, 2 insertions, 6 deletions
diff --git a/src/libnative/io/file_unix.rs b/src/libnative/io/file_unix.rs index c2b69483fa1..046d2875d55 100644 --- a/src/libnative/io/file_unix.rs +++ b/src/libnative/io/file_unix.rs @@ -493,9 +493,7 @@ fn mkstat(stat: &libc::stat) -> io::FileStat { io::FileStat { size: stat.st_size as u64, kind: kind, - perm: unsafe { - io::FilePermission::from_bits(stat.st_mode as u32) & io::AllPermissions - }, + perm: io::FilePermission::from_bits_truncate(stat.st_mode as u32), created: mktime(stat.st_ctime as u64, stat.st_ctime_nsec as u64), modified: mktime(stat.st_mtime as u64, stat.st_mtime_nsec as u64), accessed: mktime(stat.st_atime as u64, stat.st_atime_nsec as u64), diff --git a/src/libnative/io/file_win32.rs b/src/libnative/io/file_win32.rs index d721e1d67f1..3222c912dd0 100644 --- a/src/libnative/io/file_win32.rs +++ b/src/libnative/io/file_win32.rs @@ -492,9 +492,7 @@ fn mkstat(stat: &libc::stat) -> io::FileStat { io::FileStat { size: stat.st_size as u64, kind: kind, - perm: unsafe { - io::FilePermission::from_bits(stat.st_mode as u32) & io::AllPermissions - }, + perm: io::FilePermission::from_bits_truncate(stat.st_mode as u32), created: stat.st_ctime as u64, modified: stat.st_mtime as u64, accessed: stat.st_atime as u64, |
