From 268d890d11e06ef28c4f2f51ed3dba98cae8c2a3 Mon Sep 17 00:00:00 2001 From: codefaber Date: Sun, 27 Jul 2025 00:35:42 +0300 Subject: [PATCH 1/3] [libc] Fix copy/paste error in file.cpp --- libc/src/__support/File/file.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/src/__support/File/file.cpp b/libc/src/__support/File/file.cpp index 303852dbbb717..4217e73828388 100644 --- a/libc/src/__support/File/file.cpp +++ b/libc/src/__support/File/file.cpp @@ -123,7 +123,7 @@ FileIOResult File::write_unlocked_fbf(const uint8_t *data, size_t len) { FileIOResult result = platform_write(this, remainder.data(), remainder.size()); - size_t bytes_written = buf_result.value; + size_t bytes_written = result.value; // If less bytes were written than expected, then an error occurred. Return // the number of bytes that have been written from |data|. From b3f9c7a5aedbfd7a9fd120ba55556bb0836ac10f Mon Sep 17 00:00:00 2001 From: codefaber Date: Sun, 3 Aug 2025 01:24:09 +0300 Subject: [PATCH 2/3] [libc] Implement test case for copy/paste error in file.cpp --- libc/test/src/__support/File/file_test.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libc/test/src/__support/File/file_test.cpp b/libc/test/src/__support/File/file_test.cpp index b3c9f2ba49bce..ba23b30b732b0 100644 --- a/libc/test/src/__support/File/file_test.cpp +++ b/libc/test/src/__support/File/file_test.cpp @@ -493,3 +493,22 @@ TEST(LlvmLibcFileTest, WriteNothing) { ASSERT_EQ(f_lbf->close(), 0); ASSERT_EQ(f_nbf->close(), 0); } + +TEST(LlvmLibcFileTest, WriteSplit) +{ + constexpr size_t FILE_BUFFER_SIZE = 8; + char file_buffer[FILE_BUFFER_SIZE]; + StringFile *f = + new_string_file(file_buffer, FILE_BUFFER_SIZE, _IOFBF, false, "w"); + + static constexpr size_t AVAIL = 12; + f->seek(-AVAIL, SEEK_END); + + const char data[] = "hello"; + ASSERT_EQ(sizeof(data) - 1, f->write(data, sizeof(data) - 1).value); + + const char data2[] = " extra data"; + static constexpr size_t WR_EXPECTED = AVAIL - (sizeof(data) - 1); + ASSERT_EQ(WR_EXPECTED, f->write(data2, sizeof(data2) - 1).value); + EXPECT_TRUE(f->error()); +} From f165bed7aac7584c535878f2e73a743286c4ea6e Mon Sep 17 00:00:00 2001 From: codefaber Date: Sun, 3 Aug 2025 20:59:58 +0300 Subject: [PATCH 3/3] [libc] Fix formatting issue --- libc/test/src/__support/File/file_test.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libc/test/src/__support/File/file_test.cpp b/libc/test/src/__support/File/file_test.cpp index ba23b30b732b0..04ab78b07d04c 100644 --- a/libc/test/src/__support/File/file_test.cpp +++ b/libc/test/src/__support/File/file_test.cpp @@ -494,8 +494,7 @@ TEST(LlvmLibcFileTest, WriteNothing) { ASSERT_EQ(f_nbf->close(), 0); } -TEST(LlvmLibcFileTest, WriteSplit) -{ +TEST(LlvmLibcFileTest, WriteSplit) { constexpr size_t FILE_BUFFER_SIZE = 8; char file_buffer[FILE_BUFFER_SIZE]; StringFile *f =