[libcxx-commits] [libcxx] [libc++] Fix erroneous internal capacity evaluation in vector<bool> (PR #120577)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jan 5 20:17:28 PST 2025


================
@@ -115,7 +115,7 @@ class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> {
   }
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type
   __external_cap_to_internal(size_type __n) _NOEXCEPT {
-    return (__n - 1) / __bits_per_word + 1;
+    return (__n + __bits_per_word - 1) / __bits_per_word;
----------------
frederick-vs-ja wrote:

I guess we should handle the case where `__n + __bits_per_word - 1` wraps (and thus `(__n + __bits_per_word - 1) / __bits_per_word` becomes zero).

https://github.com/llvm/llvm-project/pull/120577


More information about the libcxx-commits mailing list