Skip to content

Commit fd7f69b

Browse files
authored
[libc] Fix copy/paste error in file.cpp (llvm#150802)
Fix using wrong variable due to copy/paste error. --------- Co-authored-by: codefaber <codefaber>
1 parent 0732693 commit fd7f69b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

libc/src/__support/File/file.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ FileIOResult File::write_unlocked_fbf(const uint8_t *data, size_t len) {
123123

124124
FileIOResult result =
125125
platform_write(this, remainder.data(), remainder.size());
126-
size_t bytes_written = buf_result.value;
126+
size_t bytes_written = result.value;
127127

128128
// If less bytes were written than expected, then an error occurred. Return
129129
// the number of bytes that have been written from |data|.

libc/test/src/__support/File/file_test.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,3 +493,21 @@ TEST(LlvmLibcFileTest, WriteNothing) {
493493
ASSERT_EQ(f_lbf->close(), 0);
494494
ASSERT_EQ(f_nbf->close(), 0);
495495
}
496+
497+
TEST(LlvmLibcFileTest, WriteSplit) {
498+
constexpr size_t FILE_BUFFER_SIZE = 8;
499+
char file_buffer[FILE_BUFFER_SIZE];
500+
StringFile *f =
501+
new_string_file(file_buffer, FILE_BUFFER_SIZE, _IOFBF, false, "w");
502+
503+
static constexpr size_t AVAIL = 12;
504+
f->seek(-AVAIL, SEEK_END);
505+
506+
const char data[] = "hello";
507+
ASSERT_EQ(sizeof(data) - 1, f->write(data, sizeof(data) - 1).value);
508+
509+
const char data2[] = " extra data";
510+
static constexpr size_t WR_EXPECTED = AVAIL - (sizeof(data) - 1);
511+
ASSERT_EQ(WR_EXPECTED, f->write(data2, sizeof(data2) - 1).value);
512+
EXPECT_TRUE(f->error());
513+
}

0 commit comments

Comments
 (0)