Commit 5d8ba816 authored by Victor Zverovich's avatar Victor Zverovich

Fix a segfault in test on glibc 2.26 #551

parent a9f810c1
...@@ -743,9 +743,22 @@ TEST(UtilTest, FormatSystemError) { ...@@ -743,9 +743,22 @@ TEST(UtilTest, FormatSystemError) {
fmt::format_system_error(message, EDOM, "test"); fmt::format_system_error(message, EDOM, "test");
EXPECT_EQ(fmt::format("test: {}", get_system_error(EDOM)), EXPECT_EQ(fmt::format("test: {}", get_system_error(EDOM)),
to_string(message)); to_string(message));
message.resize(0); message = fmt::memory_buffer();
fmt::format_system_error(
message, EDOM, fmt::string_view(0, std::numeric_limits<size_t>::max())); // Check if std::allocator throws on allocating max size_t / 2 chars.
size_t max_size = std::numeric_limits<size_t>::max() / 2;
bool throws_on_alloc = false;
try {
std::allocator<char> alloc;
alloc.deallocate(alloc.allocate(max_size), max_size);
} catch (std::bad_alloc) {
throws_on_alloc = true;
}
if (!throws_on_alloc) {
fmt::print("warning: std::allocator allocates {} chars", max_size);
return;
}
fmt::format_system_error(message, EDOM, fmt::string_view(0, max_size));
EXPECT_EQ(fmt::format("error {}", EDOM), to_string(message)); EXPECT_EQ(fmt::format("error {}", EDOM), to_string(message));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment