forked from fmtlib/fmt
Fix hexfloat buffer reallocation
This commit is contained in:
@ -1153,13 +1153,13 @@ int snprintf_float(T value, int precision, float_spec spec, buffer<char>& buf) {
|
|||||||
? snprintf_ptr(begin, capacity, format, precision, value)
|
? snprintf_ptr(begin, capacity, format, precision, value)
|
||||||
: snprintf_ptr(begin, capacity, format, value);
|
: snprintf_ptr(begin, capacity, format, value);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
buf.reserve(capacity + 1); // The buffer will grow exponentially.
|
buf.reserve(buf.capacity() + 1); // The buffer will grow exponentially.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
unsigned size = to_unsigned(result);
|
unsigned size = to_unsigned(result);
|
||||||
// Size equal to capacity means that the last character was truncated.
|
// Size equal to capacity means that the last character was truncated.
|
||||||
if (size >= capacity) {
|
if (size >= capacity) {
|
||||||
buf.reserve(size + 1); // Add 1 for the terminating '\0'.
|
buf.reserve(size + offset + 1); // Add 1 for the terminating '\0'.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto is_digit = [](char c) { return c >= '0' && c <= '9'; };
|
auto is_digit = [](char c) { return c >= '0' && c <= '9'; };
|
||||||
|
@ -1212,6 +1212,20 @@ TEST(FormatterTest, Precision) {
|
|||||||
"012970999954193198940908041656332452475714786901472678015935523861155013"
|
"012970999954193198940908041656332452475714786901472678015935523861155013"
|
||||||
"480352649347201937902681071074917033322268447533357208324319361e-324",
|
"480352649347201937902681071074917033322268447533357208324319361e-324",
|
||||||
format("{:.494}", 4.9406564584124654E-324));
|
format("{:.494}", 4.9406564584124654E-324));
|
||||||
|
EXPECT_EQ(
|
||||||
|
"-0X1.41FE3FFE71C9E000000000000000000000000000000000000000000000000000000"
|
||||||
|
"000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||||
|
"000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||||
|
"000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||||
|
"000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||||
|
"000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||||
|
"000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||||
|
"000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||||
|
"000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||||
|
"000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||||
|
"000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||||
|
"000000000000000000000000000000000000000000000000000P+127",
|
||||||
|
format("{:.838A}", -2.14001164E+38));
|
||||||
EXPECT_EQ("123.", format("{:#.0f}", 123.0));
|
EXPECT_EQ("123.", format("{:#.0f}", 123.0));
|
||||||
|
|
||||||
EXPECT_THROW_MSG(format("{0:.2}", reinterpret_cast<void*>(0xcafe)),
|
EXPECT_THROW_MSG(format("{0:.2}", reinterpret_cast<void*>(0xcafe)),
|
||||||
|
Reference in New Issue
Block a user