[libc-commits] [libc] fd7f69b - [libc] Fix copy/paste error in file.cpp (#150802)
via libc-commits
libc-commits at lists.llvm.org
Tue Aug 19 10:05:41 PDT 2025
Author: codefaber
Date: 2025-08-19T10:05:38-07:00
New Revision: fd7f69bfe7b694d22cd74058faa90b8a93a6d949
URL: https://github.com/llvm/llvm-project/commit/fd7f69bfe7b694d22cd74058faa90b8a93a6d949
DIFF: https://github.com/llvm/llvm-project/commit/fd7f69bfe7b694d22cd74058faa90b8a93a6d949.diff
LOG: [libc] Fix copy/paste error in file.cpp (#150802)
Fix using wrong variable due to copy/paste error.
---------
Co-authored-by: codefaber <codefaber>
Added:
Modified:
libc/src/__support/File/file.cpp
libc/test/src/__support/File/file_test.cpp
Removed:
################################################################################
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|.
diff --git a/libc/test/src/__support/File/file_test.cpp b/libc/test/src/__support/File/file_test.cpp
index b3c9f2ba49bce..04ab78b07d04c 100644
--- a/libc/test/src/__support/File/file_test.cpp
+++ b/libc/test/src/__support/File/file_test.cpp
@@ -493,3 +493,21 @@ 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());
+}
More information about the libc-commits
mailing list