Fix compiler warning in media/mtp.
BUG=27152673
Change-Id: I0a5a7f2005bd76acf4d09353305b66af3fd29e4b
diff --git a/media/mtp/Android.mk b/media/mtp/Android.mk
index 3af0956..cb7e4aa 100644
--- a/media/mtp/Android.mk
+++ b/media/mtp/Android.mk
@@ -37,7 +37,7 @@
LOCAL_MODULE:= libmtp
-LOCAL_CFLAGS := -DMTP_DEVICE -DMTP_HOST
+LOCAL_CFLAGS := -DMTP_DEVICE -DMTP_HOST -Wall -Wextra -Werror
LOCAL_SHARED_LIBRARIES := libutils libcutils liblog libusbhost libbinder
diff --git a/media/mtp/MtpDataPacket.cpp b/media/mtp/MtpDataPacket.cpp
index d0ec2a6..0381edf 100644
--- a/media/mtp/MtpDataPacket.cpp
+++ b/media/mtp/MtpDataPacket.cpp
@@ -456,7 +456,7 @@
// look at the length field to see if the data spans multiple packets
uint32_t totalLength = MtpPacket::getUInt32(MTP_CONTAINER_LENGTH_OFFSET);
allocate(totalLength);
- while (totalLength > length) {
+ while (totalLength > static_cast<uint32_t>(length)) {
request->buffer = mBuffer + length;
request->buffer_length = totalLength - length;
int ret = transfer(request);
diff --git a/media/mtp/MtpDevice.cpp b/media/mtp/MtpDevice.cpp
index 7d7ea13..a398aca 100644
--- a/media/mtp/MtpDevice.cpp
+++ b/media/mtp/MtpDevice.cpp
@@ -505,6 +505,7 @@
int remaining = size;
mRequest.reset();
mRequest.setParameter(1, handle);
+ bool error = false;
if (sendRequest(MTP_OPERATION_SEND_OBJECT)) {
// send data header
writeDataHeader(MTP_OPERATION_SEND_OBJECT, remaining);
@@ -514,7 +515,9 @@
while (remaining > 0) {
int count = read(srcFD, buffer, sizeof(buffer));
if (count > 0) {
- int written = mData.write(mRequestOut, buffer, count);
+ if (mData.write(mRequestOut, buffer, count) < 0) {
+ error = true;
+ }
// FIXME check error
remaining -= count;
} else {
@@ -523,7 +526,7 @@
}
}
MtpResponseCode ret = readResponse();
- return (remaining == 0 && ret == MTP_RESPONSE_OK);
+ return (remaining == 0 && ret == MTP_RESPONSE_OK && !error);
}
bool MtpDevice::deleteObject(MtpObjectHandle handle) {
diff --git a/media/mtp/MtpPacket.cpp b/media/mtp/MtpPacket.cpp
index bab1335..35ecb4f 100644
--- a/media/mtp/MtpPacket.cpp
+++ b/media/mtp/MtpPacket.cpp
@@ -69,7 +69,7 @@
char buffer[500];
char* bufptr = buffer;
- for (int i = 0; i < mPacketSize; i++) {
+ for (size_t i = 0; i < mPacketSize; i++) {
sprintf(bufptr, "%02X ", mBuffer[i]);
bufptr += strlen(bufptr);
if (i % DUMP_BYTES_PER_ROW == (DUMP_BYTES_PER_ROW - 1)) {
diff --git a/media/mtp/MtpProperty.cpp b/media/mtp/MtpProperty.cpp
index d58e2a4..2be2d79 100644
--- a/media/mtp/MtpProperty.cpp
+++ b/media/mtp/MtpProperty.cpp
@@ -544,7 +544,7 @@
MtpPropertyValue* result = new MtpPropertyValue[length];
for (uint32_t i = 0; i < length; i++)
if (!readValue(packet, result[i])) {
- delete result;
+ delete [] result;
return NULL;
}
return result;
diff --git a/media/mtp/MtpRequestPacket.cpp b/media/mtp/MtpRequestPacket.cpp
index 40b11b0..471967f 100644
--- a/media/mtp/MtpRequestPacket.cpp
+++ b/media/mtp/MtpRequestPacket.cpp
@@ -44,11 +44,12 @@
}
// request packet should have 12 byte header followed by 0 to 5 32-bit arguments
- if (ret >= MTP_CONTAINER_HEADER_SIZE
- && ret <= MTP_CONTAINER_HEADER_SIZE + 5 * sizeof(uint32_t)
- && ((ret - MTP_CONTAINER_HEADER_SIZE) & 3) == 0) {
- mPacketSize = ret;
- mParameterCount = (ret - MTP_CONTAINER_HEADER_SIZE) / sizeof(uint32_t);
+ const size_t read_size = static_cast<size_t>(ret);
+ if (read_size >= MTP_CONTAINER_HEADER_SIZE
+ && read_size <= MTP_CONTAINER_HEADER_SIZE + 5 * sizeof(uint32_t)
+ && ((read_size - MTP_CONTAINER_HEADER_SIZE) & 3) == 0) {
+ mPacketSize = read_size;
+ mParameterCount = (read_size - MTP_CONTAINER_HEADER_SIZE) / sizeof(uint32_t);
} else {
ALOGE("Malformed MTP request packet");
ret = -1;
diff --git a/media/mtp/MtpServer.cpp b/media/mtp/MtpServer.cpp
index 3e0f239..90f1a77 100644
--- a/media/mtp/MtpServer.cpp
+++ b/media/mtp/MtpServer.cpp
@@ -923,9 +923,7 @@
if (!mData.getUInt32(temp32)) return MTP_RESPONSE_INVALID_PARAMETER; // image bit depth
if (!mData.getUInt32(temp32)) return MTP_RESPONSE_INVALID_PARAMETER; // parent
if (!mData.getUInt16(temp16)) return MTP_RESPONSE_INVALID_PARAMETER;
- uint16_t associationType = temp16;
if (!mData.getUInt32(temp32)) return MTP_RESPONSE_INVALID_PARAMETER;
- uint32_t associationDesc = temp32; // association desc
if (!mData.getUInt32(temp32)) return MTP_RESPONSE_INVALID_PARAMETER; // sequence number
MtpStringBuffer name, created, modified;
if (!mData.getString(name)) return MTP_RESPONSE_INVALID_PARAMETER; // file name
@@ -1102,7 +1100,6 @@
}
strcpy(fileSpot, name);
- int type = entry->d_type;
if (entry->d_type == DT_DIR) {
deleteRecursive(pathbuf);
rmdir(pathbuf);