From 4c62b4f924e587da13bbba0e10a431864bded461 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 27 Sep 2016 13:58:30 -0700 Subject: Fix implicit sign casts in Parcel.h The warnings were being hidden by the use of -isystem to include frameworks/native/include. Bug: 31752268 Test: m -j Change-Id: I20d9a5712c77894f9048ef78264d7dc9f59208ea --- include/binder/Parcel.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'include/binder') diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h index 98b9835162..14fd002af3 100644 --- a/include/binder/Parcel.h +++ b/include/binder/Parcel.h @@ -531,7 +531,10 @@ template status_t Parcel::write(const LightFlattenable& val) { size_t size(val.getFlattenedSize()); if (!val.isFixedSize()) { - status_t err = writeInt32(size); + if (size > INT32_MAX) { + return BAD_VALUE; + } + status_t err = writeInt32(static_cast(size)); if (err != NO_ERROR) { return err; } @@ -562,7 +565,7 @@ status_t Parcel::read(LightFlattenable& val) const { if (err != NO_ERROR) { return err; } - size = s; + size = static_cast(s); } if (size) { void const* buffer = readInplace(size); @@ -577,7 +580,7 @@ status_t Parcel::writeVectorSize(const std::vector& val) { if (val.size() > INT32_MAX) { return BAD_VALUE; } - return writeInt32(val.size()); + return writeInt32(static_cast(val.size())); } template @@ -667,7 +670,7 @@ status_t Parcel::unsafeReadTypedVector( return UNEXPECTED_NULL; } - val->resize(size); + val->resize(static_cast(size)); for (auto& v: *val) { status = (this->*read_func)(&v); @@ -689,7 +692,7 @@ status_t Parcel::readTypedVector(std::vector* val, template status_t Parcel::readNullableTypedVector(std::unique_ptr>* val, status_t(Parcel::*read_func)(T*) const) const { - const int32_t start = dataPosition(); + const size_t start = dataPosition(); int32_t size; status_t status = readInt32(&size); val->reset(); @@ -717,7 +720,7 @@ status_t Parcel::unsafeWriteTypedVector(const std::vector& val, return BAD_VALUE; } - status_t status = this->writeInt32(val.size()); + status_t status = this->writeInt32(static_cast(val.size())); if (status != OK) { return status; @@ -773,7 +776,7 @@ status_t Parcel::readParcelableVector(std::vector* val) const { template status_t Parcel::readParcelableVector(std::unique_ptr>>* val) const { - const int32_t start = dataPosition(); + const size_t start = dataPosition(); int32_t size; status_t status = readInt32(&size); val->reset(); @@ -796,7 +799,7 @@ status_t Parcel::readParcelableVector(std::unique_ptr status_t Parcel::readParcelable(std::unique_ptr* parcelable) const { - const int32_t start = dataPosition(); + const size_t start = dataPosition(); int32_t present; status_t status = readInt32(&present); parcelable->reset(); -- cgit v1.2.3-59-g8ed1b