[all-commits] [llvm/llvm-project] bba4de: [libc++] Fix constructing `bitset` from non-null-t...

A. Jiang via All-commits all-commits at lists.llvm.org
Thu Jun 12 07:54:02 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: bba4ded3c2f94fe0de6011a6941b135b3cb0370a
      https://github.com/llvm/llvm-project/commit/bba4ded3c2f94fe0de6011a6941b135b3cb0370a
  Author: A. Jiang <de34 at live.cn>
  Date:   2025-06-12 (Thu, 12 Jun 2025)

  Changed paths:
    M libcxx/include/bitset
    M libcxx/test/std/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp

  Log Message:
  -----------
  [libc++] Fix constructing `bitset` from non-null-terminated arrays (#143691)

Unconditional evaluation of `char_traits<_CharT>::length(__str)` is problematic, because it causes
UB when `__str` points to a non-null-terminated array. We should only call `length` (currently, in
`basic_string_view`'s constructor) when `__n == npos` per [bitset.cons]/8.

Drive-by change: Reduction of conditional compilation, given that
- both `basic_string_view<_CharT>::size_type` and `basic_string<_CharT>::size_type` must be 
  `size_t`, and thus
- both `basic_string_view<_CharT>::npos` and `basic_string<_CharT>::npos` must be `size_t(-1)`.

For the type sameness in the standard wording, see:
- [string.view.template.general]
- [basic.string.general]
- [allocator.traits.types]/6
- [default.allocator.general]/1

Fixes #143684



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list