[libcxx-commits] [libcxx] [libc++] Fix constructing `bitset` from non-null-terminated arrays (PR #143691)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jun 11 05:53:13 PDT 2025
================
@@ -72,6 +72,35 @@ TEST_CONSTEXPR_CXX23 void test_char_pointer_ctor()
for (std::size_t i = 10; i < v.size(); ++i)
assert(v[i] == false);
}
+ // Verify that this constructor doesn't read over the given bound.
+ // See https://github.com/llvm/llvm-project/issues/143684
+ {
+ const char not_null_terminated[] = {'1', '0', '1', '0', '1', '0', '1', '0', '1', '0'};
+ std::bitset<N> v(not_null_terminated, 10);
+ std::size_t M = std::min<std::size_t>(v.size(), 10);
+ for (std::size_t i = 0; i < M; ++i)
+ assert(v[i] == (not_null_terminated[M - 1 - i] == '1'));
+ for (std::size_t i = 10; i < v.size(); ++i)
+ assert(v[i] == false);
----------------
philnik777 wrote:
```suggestion
assert(!v[i]);
```
Same below.
https://github.com/llvm/llvm-project/pull/143691
More information about the libcxx-commits
mailing list