diff --git a/fastboot/protocol.cpp b/fastboot/protocol.cpp index 7a333ee06..fda6f5dcb 100644 --- a/fastboot/protocol.cpp +++ b/fastboot/protocol.cpp @@ -278,19 +278,14 @@ int64_t fb_upload_data(Transport* transport, const char* outfile) { return _command_end(transport); } -#define TRANSPORT_BUF_SIZE 1024 +static constexpr size_t TRANSPORT_BUF_SIZE = 1024; static char transport_buf[TRANSPORT_BUF_SIZE]; -static int transport_buf_len; - -static int fb_download_data_sparse_write(void *priv, const void *data, int len) -{ - int r; - Transport* transport = reinterpret_cast(priv); - int to_write; - const char* ptr = reinterpret_cast(data); +static size_t transport_buf_len; +static int fb_download_data_sparse_write(void* priv, const void* data, size_t len) { + const char* ptr = static_cast(data); if (transport_buf_len) { - to_write = std::min(TRANSPORT_BUF_SIZE - transport_buf_len, len); + size_t to_write = std::min(TRANSPORT_BUF_SIZE - transport_buf_len, len); memcpy(transport_buf + transport_buf_len, ptr, to_write); transport_buf_len += to_write; @@ -298,9 +293,10 @@ static int fb_download_data_sparse_write(void *priv, const void *data, int len) len -= to_write; } + Transport* transport = static_cast(priv); if (transport_buf_len == TRANSPORT_BUF_SIZE) { - r = _command_write_data(transport, transport_buf, TRANSPORT_BUF_SIZE); - if (r != TRANSPORT_BUF_SIZE) { + int64_t r = _command_write_data(transport, transport_buf, TRANSPORT_BUF_SIZE); + if (r != static_cast(TRANSPORT_BUF_SIZE)) { return -1; } transport_buf_len = 0; @@ -311,9 +307,9 @@ static int fb_download_data_sparse_write(void *priv, const void *data, int len) g_error = "internal error: transport_buf not empty"; return -1; } - to_write = round_down(len, TRANSPORT_BUF_SIZE); - r = _command_write_data(transport, ptr, to_write); - if (r != to_write) { + size_t to_write = round_down(len, TRANSPORT_BUF_SIZE); + int64_t r = _command_write_data(transport, ptr, to_write); + if (r != static_cast(to_write)) { return -1; } ptr += to_write;