@@ -3452,8 +3452,9 @@ class basic_string {
34523452 // Update the string length appropriately
34533453 if (actual_count > string_length) {
34543454 string_start[actual_count] = ' \0 ' ;
3455- // ! Knowing the layout of the string, we can perform this operation safely,
3456- // ! even if its located on stack.
3455+ // Safe for both SSO and heap strings: on little-endian, internal.length
3456+ // overlaps with LSB of external.length, so += affects only the length byte.
3457+ // On big-endian, the struct layout places them at matching positions.
34573458 string_.external .length += actual_count - string_length;
34583459 }
34593460 else { sz_string_erase (&string_, actual_count, SZ_SIZE_MAX); }
@@ -4190,8 +4191,9 @@ bool basic_string<char_type_, allocator_>::try_resize(size_type count, value_typ
41904191 if (count > string_length) {
41914192 sz_fill (string_start + string_length, count - string_length, character);
41924193 string_start[count] = ' \0 ' ;
4193- // Knowing the layout of the string, we can perform this operation safely,
4194- // even if its located on stack.
4194+ // Safe for both SSO and heap strings: on little-endian, internal.length
4195+ // overlaps with LSB of external.length, so += affects only the length byte.
4196+ // On big-endian, the struct layout places them at matching positions.
41954197 string_.external .length += count - string_length;
41964198 }
41974199 else { sz_string_erase (&string_, count, SZ_SIZE_MAX); }
0 commit comments