@aktau Got catch.

I think your mockup only had switched operands in the subtraction:

> `size_t to_delete = (new_len < old_len) ? (size_t)(new_len - old_len) : 0;`

`extra -= to_delete` should be correct (`i == to_delete` when the loop is finished).