diff options
| author | Ahmed Bougacha <ahmed.bougacha@gmail.com> | 2017-04-26 00:48:28 +0000 |
|---|---|---|
| committer | Ahmed Bougacha <ahmed.bougacha@gmail.com> | 2017-04-26 00:48:28 +0000 |
| commit | 9547aabb26148f4eb5cfa1c5ccba0fe4ab7bf4fa (patch) | |
| tree | 5eff020f30c62bab80fac97a81053c87f874d14c /llvm | |
| parent | d91fb8c367186cac1b55be88314385df1959ef10 (diff) | |
| download | bcm5719-llvm-9547aabb26148f4eb5cfa1c5ccba0fe4ab7bf4fa.tar.gz bcm5719-llvm-9547aabb26148f4eb5cfa1c5ccba0fe4ab7bf4fa.zip | |
[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
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/Support/FileSystem.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/include/llvm/Support/FileSystem.h b/llvm/include/llvm/Support/FileSystem.h index 29515c231bc..e3c5de7fbe6 100644 --- a/llvm/include/llvm/Support/FileSystem.h +++ b/llvm/include/llvm/Support/FileSystem.h @@ -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 { |

