From 5672db086a24fd5e45e74f923882e91eafb4fef2 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sat, 17 Jan 2009 22:03:36 +0000 Subject: lt sync 3187 --- libtorrent/include/libtorrent/version.hpp | 1 + libtorrent/src/assert.cpp | 5 ++++- libtorrent/src/identify_client.cpp | 7 ++++++- libtorrent/src/storage.cpp | 29 ++++++++++++++++++++++++++--- libtorrent/src/torrent.cpp | 2 +- 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/libtorrent/include/libtorrent/version.hpp b/libtorrent/include/libtorrent/version.hpp index ac6cadf3a..ee376cc21 100644 --- a/libtorrent/include/libtorrent/version.hpp +++ b/libtorrent/include/libtorrent/version.hpp @@ -37,5 +37,6 @@ POSSIBILITY OF SUCH DAMAGE. #define LIBTORRENT_VERSION_MINOR 14 #define LIBTORRENT_VERSION "0.14.2.0" +#define LIBTORRENT_REVISION "$Rev: 3169 $" #endif diff --git a/libtorrent/src/assert.cpp b/libtorrent/src/assert.cpp index 26307a95b..b98201d95 100644 --- a/libtorrent/src/assert.cpp +++ b/libtorrent/src/assert.cpp @@ -86,6 +86,7 @@ std::string demangle(char const* name) #include #include #include +#include "libtorrent/version.hpp" // execinfo.h is available in the MacOS X 10.5 SDK. #if (defined __linux__ || (defined __APPLE__ && MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)) @@ -117,10 +118,12 @@ void assert_fail(char const* expr, int line, char const* file, char const* funct fprintf(stderr, "assertion failed. Please file a bugreport at " "http://code.rasterbar.com/libtorrent/newticket\n" "Please include the following information:\n\n" + "version: " LIBTORRENT_VERSION "\n" + "%s\n" "file: '%s'\n" "line: %d\n" "function: %s\n" - "expression: %s\n", file, line, function, expr); + "expression: %s\n", LIBTORRENT_REVISION, file, line, function, expr); print_backtrace("stack:"); diff --git a/libtorrent/src/identify_client.cpp b/libtorrent/src/identify_client.cpp index 9eb0fd3c9..1b0b3be67 100755 --- a/libtorrent/src/identify_client.cpp +++ b/libtorrent/src/identify_client.cpp @@ -53,9 +53,14 @@ namespace using namespace libtorrent; + bool is_digit(char c) + { + return c >= '0' && c <= '9'; + } + int decode_digit(char c) { - if (std::isdigit(c)) return c - '0'; + if (is_digit(c)) return c - '0'; return unsigned(c) - 'A' + 10; } diff --git a/libtorrent/src/storage.cpp b/libtorrent/src/storage.cpp index 82402629f..905ee1da7 100755 --- a/libtorrent/src/storage.cpp +++ b/libtorrent/src/storage.cpp @@ -970,15 +970,26 @@ namespace libtorrent int actual_read = int(in->read(buf + buf_pos, read_bytes, ec)); - if (read_bytes != actual_read || ec) + if (ec) + { + set_error(m_save_path / file_iter->path, ec); + return -1; + } + + if (read_bytes != actual_read) { // the file was not big enough - if (actual_read > 0) buf_pos += actual_read; if (!fill_zero) { +#ifdef TORRENT_WINDOWS + ec = error_code(ERROR_READ_FAULT, get_system_category()); +#else + ec = error_code(EIO, get_posix_category()); +#endif set_error(m_save_path / file_iter->path, ec); return -1; } + if (actual_read > 0) buf_pos += actual_read; std::memset(buf + buf_pos, 0, size - buf_pos); return size; } @@ -1111,12 +1122,24 @@ namespace libtorrent error_code ec; size_type written = out->write(buf + buf_pos, write_bytes, ec); - if (written != write_bytes || ec) + if (ec) { set_error(m_save_path / file_iter->path, ec); return -1; } + if (write_bytes != written) + { + // the file was not big enough +#ifdef TORRENT_WINDOWS + ec = error_code(ERROR_READ_FAULT, get_system_category()); +#else + ec = error_code(EIO, get_posix_category()); +#endif + set_error(m_save_path / file_iter->path, ec); + return -1; + } + left_to_write -= write_bytes; buf_pos += write_bytes; TORRENT_ASSERT(buf_pos >= 0); diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index efb97a77d..0f6ee3f18 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -1174,7 +1174,7 @@ namespace libtorrent const std::vector& dl_queue = m_picker->get_download_queue(); - const int blocks_per_piece = piece_size / m_block_size; + const int blocks_per_piece = (piece_size + m_block_size - 1) / m_block_size; for (std::vector::const_iterator i = dl_queue.begin(); i != dl_queue.end(); ++i) -- cgit