Fix some undefined behavior in __hash_table. Thanks to vsk for the report and the patch. Reviewed as https://reviews.llvm.org/D33588.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@304617 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2017-06-03 00:08:32 +00:00
parent c689592890
commit b1d8bca727
2 changed files with 81 additions and 1 deletions

View File

@@ -137,7 +137,7 @@ inline _LIBCPP_INLINE_VISIBILITY
size_t
__next_hash_pow2(size_t __n)
{
return size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1));
return __n < 2 ? __n : (size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1)));
}