From ca9122861a0a237152a9be270a622c5e6d33850f Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 2 Nov 2011 04:45:22 +0000 Subject: [PATCH] merged unaligned write fix over from RC_0_15 --- src/storage.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/storage.cpp b/src/storage.cpp index d64824abf..88973cfd4 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1343,12 +1343,13 @@ ret: TORRENT_ASSERT((aligned_size & size_align) == 0); size_type actual_file_size = file_handle->get_size(ec); - if (ec) return -1; + if (ec && ec != make_error_code(boost::system::errc::no_such_file_or_directory)) return -1; // allocate a temporary, aligned, buffer aligned_holder aligned_buf(aligned_size); file::iovec_t b = {aligned_buf.get(), aligned_size}; - if (aligned_start < actual_file_size) // we have something to read + // we have something to read + if (aligned_start < actual_file_size && !ec) { size_type ret = file_handle->readv(aligned_start, &b, 1, ec); if (ret < 0) @@ -1358,6 +1359,8 @@ ret: } } + ec.clear(); + // OK, we read the portion of the file. Now, overlay the buffer we're writing char* write_buf = aligned_buf.get() + start_adjust;