Fix harmless math errors in folly::Format stack buffer manipulation.
Summary:
The math that figures out the biggest possible formatted
number, for a stack buffer size, computed 65 bytes for "binary" format:
```
// #b: 0b prefix + 64 bytes = 65 bytes
```
But with that 2-byte "0b" prefix this of course sums to 66 bytes.
This turns out to be harmless, rather than causing a buffer overrun,
because the buffer size additionally reserves two more bytes for
"prefix shenanigans", which are redundant with the two prefix bytes
explicitly reserved for "0b" (but in this case were covering up the
off-by-one error).
I cleaned up a few things while I was there:
- I fixed the size computation for binary buffers, including
making it use kMaxBinaryLength, which is based on `sizeof(uintmax_t)`,
rather than hardcoding `64`.
- I removed the redundant prefix shenanigans reservation.
- I fixed the places that were reserving two bytes for a prefix
(like "0x") right after asserting that no prefix is allowed,
e.g. for chars and decimal numbers.
- I stopped reserving a byte for NUL, because these days this code
uses folly::StringPiece and never NUL-terminates.
Reviewed By: yfeldblum
Differential Revision: D20694395
fbshipit-source-id: 6658675d9993d2fe223675db55c8040ddee143a8
Showing
Please register or sign in to comment