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

Peng Liu via libcxx-commits libcxx-commits at lists.llvm.org
Thu Dec 19 17:01:26 PST 2024


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

>From 12182438439d913cdf83a48e1e77269d9212274d Mon Sep 17 00:00:00 2001
From: Peng Liu <winner245 at hotmail.com>
Date: Thu, 19 Dec 2024 08:36:10 -0500
Subject: [PATCH] Fix arithmetic underflow

---
 libcxx/include/__vector/vector_bool.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__vector/vector_bool.h b/libcxx/include/__vector/vector_bool.h
index 525fc35b26cc9e..bcc272380fed5b 100644
--- a/libcxx/include/__vector/vector_bool.h
+++ b/libcxx/include/__vector/vector_bool.h
@@ -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;
   }
 
 public:



More information about the libcxx-commits mailing list