[libcxx][NFC] Tidy up calculation of __nbuf in num_put::do_put, and add comments
In 07ef8e67 and 3ed9f6eb, `__nbuf` started to diverge from the amount of space that was actually needed for the buffer. For 32-bit longs for example, we allocate a buffer that is one larger than needed. Moreover, it is no longer clear exactly where the extra +1 or +2 comes from - they're just numbers pulled from thin air. This PR cleans up how `__nbuf` is calculated, and adds comments to further clarify where each part comes from. Specifically, it corrects the underestimation of the max size buffer needed that the above two commits had to compensate for. The root cause looks to be the use of signed type parameters to numeric_limits<>::digits. Since digits only counts non-sign bits, the calculation was acting as though (for a signed 64-bit type) the longest value we would print was 2^63 in octal. However, printing in octal treats values as unsigned, so it is actually 2^64. Thus, using unsigned types and changing the final +2 to a +1 is probably a better option. Reviewed By: #libc, ldionne, Mordante Differential Revision: https://reviews.llvm.org/D103339
Loading
Please register or sign in to comment