<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/125188>125188</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc++] basic_string::max_size() is broken for small sizes
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
philnik777
</td>
</tr>
</table>
<pre>
`max_size()` currently checks if the allocator's `max_size() <= numeric_limits<size_type>::max() / 2`, but then subtracts an alignment, causing an overflow for values less than the alignment. We should probably just diagnose when the `max_size()` of the allocator is so small that our string implementation is just broken (e.g. `max_size() < SSO size`).
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxskstu5CwQhZ8Gb0qxDPi68CKXv7f_IotZtoCutkkwtCjopOfpR3Q6M9FMJEuWijqcqo-jiOziEWfWPbDuqVI5rSHOp9U6b1-HYah0OFxm1jebet-T_YlMjExMrG_A5BjRJ3cBs6J5JbBHSCuCci4YlUJkYiD4RwpMPjL5BD5vGK3ZO7vZREw-lpZ9upyQyf-YvGfyflPvnxqxA8H6holH0DkVHw-UdYrKJALlQTm7-A19Ki1GZbJ-KfVwxnh04Q2OIcJZuYwEDokgrcrf5r0pa_iBQGvI7gCnGLTS7gIvmRIcrFp8IIS34ltE3xIJfwEAS0ABaFPOFb8EIUegFMtsdjs5LLYq2eBL69VKx_CKHpgYsV7q7_HB8_P_cC0VIlNdHWZ5mOSkKpz5IEfJu5b31ToPB9O1RistJ-RTy9tWdcM4YiuOQ4ODqewsGtE1XPJmElL2dadkP7WSc5SCt71hbYObsq527rzVIS6VJco4c9Hxcayc0ujomh4hnNWGiYfrJ0qa4lxUdzovxNrGWUr0555kk7vm7ousewKtyJr9B6PfKfi6v6VPRuVFP9iWY6pydPOa0omKTuyY2C02rVnXJmxM7Irz7Xd3iuEFTWJid12HmNjdNjrP4lcAAAD__0wq_fk">