From 1b5222af1b94c06c5e347cb94a9863a207d9efc3 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 7 Nov 2026 16:38:44 -0800 Subject: [PATCH] Clarify ostream capacity comment and strengthen zero buffer test The old test only caught the overflow under ASan. --- src/os.cc | 2 +- test/os-test.cc | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/os.cc b/src/os.cc index f0e71aac..927deaff 100644 --- a/src/os.cc +++ b/src/os.cc @@ -383,7 +383,7 @@ void ostream::grow(buffer& buf, size_t) { ostream::ostream(cstring_view path, const detail::ostream_params& params) : buffer(grow), file_(path, params.oflag) { - // grow() can only make room by flushing, so the buffer can't be empty. + // Flushing is the only way to make room, so the capacity can't be zero. size_t size = max_of(params.buffer_size, 1); set(new char[size], size); } diff --git a/test/os-test.cc b/test/os-test.cc index 24f96ed9..43303f98 100644 --- a/test/os-test.cc +++ b/test/os-test.cc @@ -298,10 +298,11 @@ TEST(ostream_test, buffer_size) { TEST(ostream_test, zero_buffer_size) { auto test_file = uniq_file_name(__LINE__); fmt::ostream out = fmt::output_file(test_file, fmt::buffer_size = 0); - out.print("{}{}", 'f', "oo"); - out.close(); + out.print("{}{}", 'A', " byte late!"); file in(test_file, file::RDONLY); - EXPECT_READ(in, "foo"); + EXPECT_READ(in, "A byte late"); + out.close(); + EXPECT_READ(in, "!"); } TEST(ostream_test, truncate) {