<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60010>60010</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
The C function `ecvt(...)` outputs a string one digit longer than expected
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tim-lyon
</td>
</tr>
</table>
<pre>
Given a floating point number consisting of repeating digit `9`, the function `ecvt` incorrectly returns a string of length `n + 1` where `n` is the expected length.
Minimal example:
```C++
#include <iostream>
#include <stdlib.h>
int main() {
int dec, sign;
std::cout << ecvt(999, 2, &dec, &sign);
}
```
- Expected output: `10` (two digits, as per second argument)
- Clang (trunk): `100` (three digits)
- gcc: `100` (same issue)
- MSVC: `10` (as expected)
Example in compiler explorer
https://godbolt.org/z/zYzfT7EP6
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsk82OpDYQx5_GXEqNjE3TcOAw09Od00qRsoqUozEFODE2souZnX36yDTLjmZXMoVUHz-X_6VSMZrRIbbs_MzOL5laafKhJTOf7Lt3Wef79_YP84oOFAzWKzJuhMUbR-DWucMA2rto4ub3AwRc8JHUm9EQsIo3rOJMXIEmhGF1mox3yY_6lVjFwTjtQ0BN9h0C0hpcBAWRwo606EaaUoUDJp6hSEVvEwbcfBsibnT8tqAm7PeSnPEXxp8e9otxZlYW8JuaF4tM7v7U3HauTDyn8_AKaZy2a4_A5NX4SAHVzOTtd-FIvTVdPv0MbzZpNCvjmKiZaIBddjZAivSokyhJfiaPSKQ-dSaftF8psZm8wiaUqJumSRUiGSaqHcBEtTFEc2DY5eXT2z62dYLbD5n8SstKTD4lIYuUCEzU9OYfw4uJryIsGCCi9q4HFcZ1Rkfpup12tcqNW11Y3X9bHzvvAE4B8UAehaPWv6RGNSOYGFf8kPjlr7-vn5tU8Zj2kfmwt8eAwTjQfl6MxZBSrQ8YHhkT0RKTzOLOxH30fect5T6MTNy_p--f78PXy-3PKutb2TeyURm2RXWRlRRFXWdTW8hLrbiQvBtqgefzWRb1WRdlVw4drxudmVakcFHI4lI2ZZ1XJR-6UoiSYzVUhWAlx1kZm1v7Oqe7s-3VbcV5wTOrOrRxW0ohHL79kESkHQ1tqjl16xhZya2JFH9SyJDF9uuEcP112USd53mSq-L77D9umttnBNa7EQPQpNwhcrYG234SztC0drn2MxP31MD-Oy3B_4uamLhvbUcm7tuz_g8AAP__H_VSDg">