Skip to content

[libc++] Fix erroneous internal capacity evaluation in vector<bool> #120577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libcxx/include/__vector/vector_bool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 > 0 ? (__n - 1) / __bits_per_word + 1 : size_type(0);
}

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ TEST_CONSTEXPR_CXX20 void test_vector_flip(std::size_t n, Allocator a) {
}

TEST_CONSTEXPR_CXX20 bool tests() {
// Test empty vectors
test_vector_flip(0, std::allocator<bool>());
test_vector_flip(0, min_allocator<bool>());
test_vector_flip(0, test_allocator<bool>(5));

// Test small vectors with different allocators
test_vector_flip(3, std::allocator<bool>());
test_vector_flip(3, min_allocator<bool>());
Expand Down
Loading