diff options
| -rw-r--r-- | include/binder/Parcel.h | 19 |
1 files changed, 11 insertions, 8 deletions
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<typename T> status_t Parcel::write(const LightFlattenable<T>& 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<int32_t>(size)); if (err != NO_ERROR) { return err; } @@ -562,7 +565,7 @@ status_t Parcel::read(LightFlattenable<T>& val) const { if (err != NO_ERROR) { return err; } - size = s; + size = static_cast<size_t>(s); } if (size) { void const* buffer = readInplace(size); @@ -577,7 +580,7 @@ status_t Parcel::writeVectorSize(const std::vector<T>& val) { if (val.size() > INT32_MAX) { return BAD_VALUE; } - return writeInt32(val.size()); + return writeInt32(static_cast<int32_t>(val.size())); } template<typename T> @@ -667,7 +670,7 @@ status_t Parcel::unsafeReadTypedVector( return UNEXPECTED_NULL; } - val->resize(size); + val->resize(static_cast<size_t>(size)); for (auto& v: *val) { status = (this->*read_func)(&v); @@ -689,7 +692,7 @@ status_t Parcel::readTypedVector(std::vector<T>* val, template<typename T> status_t Parcel::readNullableTypedVector(std::unique_ptr<std::vector<T>>* 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<T>& val, return BAD_VALUE; } - status_t status = this->writeInt32(val.size()); + status_t status = this->writeInt32(static_cast<int32_t>(val.size())); if (status != OK) { return status; @@ -773,7 +776,7 @@ status_t Parcel::readParcelableVector(std::vector<T>* val) const { template<typename T> status_t Parcel::readParcelableVector(std::unique_ptr<std::vector<std::unique_ptr<T>>>* 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<std::vector<std::unique_pt template<typename T> status_t Parcel::readParcelable(std::unique_ptr<T>* parcelable) const { - const int32_t start = dataPosition(); + const size_t start = dataPosition(); int32_t present; status_t status = readInt32(&present); parcelable->reset(); |