Skip to content

Commit c20059e

Browse files
committed
Fix undefined in format-test
When `MoveCtor` performs `check_move_buffer`, the buffer allocator becomes null, but then `MoveCtor` attempts to use it to allocate a dynamic buffer. This succeeds nevertheless because a typical `std::allocator<char>::allocate` does not use `this`, so it does not crash when `this` is null. Fixes fmtlib#1344
1 parent b66bb6b commit c20059e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

test/format-test.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ static void check_move_buffer(
271271
EXPECT_EQ(alloc, buffer2.get_allocator().get());
272272
}
273273

274-
TEST(MemoryBufferTest, MoveCtor) {
274+
TEST(MemoryBufferTest, MoveCtorInlineBuffer) {
275275
std::allocator<char> alloc;
276276
basic_memory_buffer<char, 5, TestAllocator> buffer((TestAllocator(&alloc)));
277277
const char test[] = "test";
@@ -281,6 +281,13 @@ TEST(MemoryBufferTest, MoveCtor) {
281281
// dynamic allocation.
282282
buffer.push_back('a');
283283
check_move_buffer("testa", buffer);
284+
}
285+
286+
TEST(MemoryBufferTest, MoveCtorDynamicBuffer) {
287+
std::allocator<char> alloc;
288+
basic_memory_buffer<char, 5, TestAllocator> buffer((TestAllocator(&alloc)));
289+
const char test[] = "testa";
290+
buffer.append(test, test + 5);
284291
const char* inline_buffer_ptr = &buffer[0];
285292
// Adding one more character causes the content to move from the inline to
286293
// a dynamically allocated buffer.

0 commit comments

Comments
 (0)