forked from OSchip/llvm-project
[Support] Avoid UB in sys::fs::perms::operator~. NFC.
This was exposed in r297945 and r301220: the intermediate complement is a 32-bit value, and casting it to 'perms' invokes UB. llvm-svn: 301373
This commit is contained in:
parent
d91fb8c367
commit
9547aabb26
|
@ -116,7 +116,9 @@ inline perms &operator&=(perms &l, perms r) {
|
|||
return l;
|
||||
}
|
||||
inline perms operator~(perms x) {
|
||||
return static_cast<perms>(~static_cast<unsigned short>(x));
|
||||
// Avoid UB by explicitly truncating the (unsigned) ~ result.
|
||||
return static_cast<perms>(
|
||||
static_cast<unsigned short>(~static_cast<unsigned short>(x)));
|
||||
}
|
||||
|
||||
class UniqueID {
|
||||
|
|
Loading…
Reference in New Issue