From 6264129434e511da38faedeb5739c3e4bd4a710e Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Thu, 30 Jul 2015 19:58:10 -0700 Subject: [PATCH] Make clear of the data length sent by write_packet. Change-Id: If51b4feaa19a710874999ad7e6131ff2e56a9f8a --- adb/transport.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/adb/transport.cpp b/adb/transport.cpp index 87aff88e8..4a273c482 100644 --- a/adb/transport.cpp +++ b/adb/transport.cpp @@ -126,19 +126,18 @@ static void dump_packet(const char* name, const char* func, apacket* p) { static int read_packet(int fd, const char* name, apacket** ppacket) { - char *p = (char*)ppacket; /* really read a packet address */ - int r; - int len = sizeof(*ppacket); - char buff[8]; + char buff[8]; if (!name) { snprintf(buff, sizeof buff, "fd=%d", fd); name = buff; } + char* p = reinterpret_cast(ppacket); /* really read a packet address */ + int len = sizeof(apacket*); while(len > 0) { - r = adb_read(fd, p, len); + int r = adb_read(fd, p, len); if(r > 0) { len -= r; - p += r; + p += r; } else { D("%s: read_packet (fd=%d), error ret=%d errno=%d: %s\n", name, fd, r, errno, strerror(errno)); if((r < 0) && (errno == EINTR)) continue; @@ -155,20 +154,18 @@ read_packet(int fd, const char* name, apacket** ppacket) static int write_packet(int fd, const char* name, apacket** ppacket) { - char *p = (char*) ppacket; /* we really write the packet address */ - int r, len = sizeof(ppacket); char buff[8]; if (!name) { snprintf(buff, sizeof buff, "fd=%d", fd); name = buff; } - if (ADB_TRACING) { dump_packet(name, "to remote", *ppacket); } - len = sizeof(ppacket); + char* p = reinterpret_cast(ppacket); /* we really write the packet address */ + int len = sizeof(apacket*); while(len > 0) { - r = adb_write(fd, p, len); + int r = adb_write(fd, p, len); if(r > 0) { len -= r; p += r;