Skip to content

Conversation

@winner245
Copy link
Contributor

@winner245 winner245 commented Dec 19, 2024

This PR fixes the erroneous internal capacity evaluation in vector<bool>, which caused a subsequent SIGSEGV error when calling flip() on vector<bool>. By fixing the internal capacity evaluation, the SIGSEGV is automatically resolved.

Closes #121726.

@winner245 winner245 requested a review from a team as a code owner December 19, 2024 13:37
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Dec 19, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 19, 2024

@llvm/pr-subscribers-libcxx

Author: Peng Liu (winner245)

Changes

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

1 Files Affected:

  • (modified) libcxx/include/__vector/vector_bool.h (+1-1)
diff --git a/libcxx/include/__vector/vector_bool.h b/libcxx/include/__vector/vector_bool.h
index 36eb7f350ac406..2409626ad20d9c 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:

@winner245 winner245 changed the title [libc++] Fix arithmetic underflow in internal capacity evaluation for vector<bool> [libc++] Fix erroneous internal capacity evaluation for vector<bool> Jan 6, 2025
@winner245 winner245 changed the title [libc++] Fix erroneous internal capacity evaluation for vector<bool> [libc++] Fix erroneous internal capacity evaluation in vector<bool> Jan 6, 2025
@frederick-vs-ja frederick-vs-ja merged commit 6c06253 into llvm:main Jan 9, 2025
62 checks passed
@winner245 winner245 deleted the fix-underflow branch January 9, 2025 12:45
philnik777 added a commit to philnik777/llvm-project that referenced this pull request Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[libc++] Erroneous internal capacity evaluation causes SIGSEGV in vector<bool>

4 participants