mirror of
https://github.com/fmtlib/fmt.git
synced 2026-11-09 14:50:24 +08:00
Clarify ostream capacity comment and strengthen zero buffer test
The old test only caught the overflow under ASan.
This commit is contained in:
parent
a9e41a6df2
commit
1b5222af1b
@ -383,7 +383,7 @@ void ostream::grow(buffer<char>& buf, size_t) {
|
||||
|
||||
ostream::ostream(cstring_view path, const detail::ostream_params& params)
|
||||
: buffer<char>(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<size_t>(params.buffer_size, 1);
|
||||
set(new char[size], size);
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user