Skip to content

Commit

Permalink
Fix a segfault in test on glibc 2.26 #551, take 2
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Aug 10, 2017
1 parent 6655e80 commit 032c838
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions test/util-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,21 @@ TEST(UtilTest, FormatSystemError) {
fmt::format_system_error(message, EDOM, "test");
EXPECT_EQ(fmt::format("test: {}", get_system_error(EDOM)), message.str());
message.clear();
fmt::format_system_error(
message, EDOM, fmt::StringRef(0, std::numeric_limits<ssize_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::StringRef(0, max_size));
EXPECT_EQ(fmt::format("error {}", EDOM), message.str());
}

Expand Down

0 comments on commit 032c838

Please sign in to comment.