Skip to content

Commit

Permalink
fixup! [libc++][string] Remove potential non-trailing 0-length array
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-sans-paille committed Aug 29, 2024
1 parent f3302f0 commit d5c8412
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions libcxx/include/string
Original file line number Diff line number Diff line change
Expand Up @@ -750,22 +750,22 @@ struct __init_with_sentinel_tag {};

#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
template <class _CharT, size_t __min_cap, size_t _Padding = sizeof(_CharT) - 1>
struct __short_impl {
struct __short_layout_alternate {
_CharT __data_[__min_cap];
unsigned char __padding_[_Padding];
unsigned char __size_ : 7;
unsigned char __is_long_ : 1;
};

template <class _CharT, size_t __min_cap>
struct __short_impl<_CharT, __min_cap, 0> {
struct __short_layout_alternate<_CharT, __min_cap, 0> {
_CharT __data_[__min_cap];
unsigned char __size_ : 7;
unsigned char __is_long_ : 1;
};
#else
template <class _CharT, size_t __min_cap, size_t _Padding = sizeof(_CharT) - 1>
struct __short_impl {
struct __short_layout_classic {
struct _LIBCPP_PACKED {
unsigned char __is_long_ : 1;
unsigned char __size_ : 7;
Expand All @@ -774,7 +774,7 @@ struct __short_impl {
_CharT __data_[__min_cap];
};
template <class _CharT, size_t __min_cap>
struct __short_impl<_CharT, __min_cap, 0> {
struct __short_layout_classic<_CharT, __min_cap, 0> {
struct _LIBCPP_PACKED {
unsigned char __is_long_ : 1;
unsigned char __size_ : 7;
Expand Down Expand Up @@ -929,7 +929,11 @@ private:

#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT

using __short = __short_impl<value_type, __min_cap>;
#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
using __short = __short_layout_alternate<value_type, __min_cap>;
#else
using __short = __short_layout_classic<value_type, __min_cap>;
#endif
static_assert(sizeof(__short) == (sizeof(value_type) * (__min_cap + 1)), "__short has an unexpected size.");

union __rep {
Expand Down

0 comments on commit d5c8412

Please sign in to comment.