@@ -198,12 +198,14 @@ _LIBCPP_HIDE_FROM_ABI basic_format_arg<_Context> __create_format_arg(_Tp& __valu
198198 else if constexpr (__arg == __arg_t ::__string_view)
199199 // Using std::size on a character array will add the NUL-terminator to the size.
200200 if constexpr (__is_bounded_array_of<_Dp, __context_char_type>) {
201- if (const auto __pzero = char_traits<__context_char_type>::find (__value, extent_v<_Dp>, __context_char_type{}))
201+ const auto __pbegin = std::begin (__value);
202+ if (const _Dp* __pzero = char_traits<__context_char_type>::find (__pbegin, extent_v<_Dp>, __context_char_type{})) {
202203 return basic_format_arg<_Context>{
203- __arg, basic_string_view<__context_char_type>{__value, static_cast <size_t >(__pzero - __value)}};
204- else
205- // The behavior is undefined in this case.
206- return basic_format_arg<_Context>{__arg, basic_string_view<__context_char_type>{__value, extent_v<_Dp>}};
204+ __arg, basic_string_view<__context_char_type>{__pbegin, static_cast <size_t >(__pzero - __pbegin)}};
205+ } else {
206+ // Per [format.arg]/5, the behavior is undefined because the array is not null-terminated.
207+ return basic_format_arg<_Context>{__arg, basic_string_view<__context_char_type>{__pbegin, extent_v<_Dp>}};
208+ }
207209 } else
208210 // When the _Traits or _Allocator are different an implicit conversion will fail.
209211 return basic_format_arg<_Context>{__arg, basic_string_view<__context_char_type>{__value.data (), __value.size ()}};
0 commit comments