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
diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h
index 98b9835..14fd002 100644
--- a/include/binder/Parcel.h
+++ b/include/binder/Parcel.h
@@ -531,7 +531,10 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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();