mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-23 10:50:05 +00:00
Use a heuristic to detect empty strftime result (#367)
This commit is contained in:
parent
1a23f9c274
commit
a5d0adf395
@ -36,6 +36,13 @@ void format(BasicFormatter<char, ArgFormatter> &f,
|
|||||||
buffer.resize(start + count);
|
buffer.resize(start + count);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (size >= format.size() * 256) {
|
||||||
|
// If the buffer is 256 times larger than the format string, assume
|
||||||
|
// that `strftime` gives an empty result. There doesn't seem to be a
|
||||||
|
// better way to distinguish the two cases:
|
||||||
|
// https://github.com/fmtlib/fmt/issues/367
|
||||||
|
break;
|
||||||
|
}
|
||||||
const std::size_t MIN_GROWTH = 10;
|
const std::size_t MIN_GROWTH = 10;
|
||||||
buffer.reserve(buffer.capacity() + (size > MIN_GROWTH ? size : MIN_GROWTH));
|
buffer.reserve(buffer.capacity() + (size > MIN_GROWTH ? size : MIN_GROWTH));
|
||||||
}
|
}
|
||||||
|
@ -27,3 +27,7 @@ TEST(TimeTest, GrowBuffer) {
|
|||||||
std::time_t t = std::time(0);
|
std::time_t t = std::time(0);
|
||||||
fmt::format(s, *std::localtime(&t));
|
fmt::format(s, *std::localtime(&t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(TimeTest, EmptyResult) {
|
||||||
|
EXPECT_EQ("", fmt::format("{}", std::tm()));
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user