]> git.lizzy.rs Git - rust.git/commit
Make `from_bits` in `bitflags!` safe; add `from_bits_truncate`
authorAaron Turon <aturon@mozilla.com>
Wed, 14 May 2014 21:39:16 +0000 (14:39 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 15 May 2014 20:50:33 +0000 (13:50 -0700)
commit912a9675c0b7f9e8c836983e525b180c48693925
tree3543072ddff4c87068ed5b191db6b57660662fb7
parentd547de998d33e5b688533f4159ea997c940d9431
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
src/libnative/io/file_unix.rs
src/libnative/io/file_win32.rs
src/librustuv/file.rs
src/libstd/bitflags.rs