summaryrefslogtreecommitdiff
path: root/Parcel.cpp
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2019-07-02 07:40:53 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-07-02 07:40:53 +0000
commite4d5cd07809019d24b12b4b47824d2c8c89424cb (patch)
tree7881f8564414e0140154f89c0a2a285a664e8cb6 /Parcel.cpp
parentcb9f36d7c4b83d2126f0e0b699ca205d7dddabe2 (diff)
parentef9f41a62876156a30b21d56d7ea487730a0b126 (diff)
downloadlibhwbinder-e4d5cd07809019d24b12b4b47824d2c8c89424cb.tar.gz
Merge "DO NOT MERGE - Merge qt-dev-plus-aosp-without-vendor (5699924) into stage-aosp-master" into stage-aosp-master
Diffstat (limited to 'Parcel.cpp')
-rw-r--r--Parcel.cpp49
1 files changed, 26 insertions, 23 deletions
diff --git a/Parcel.cpp b/Parcel.cpp
index 36ea3bc..6d8f11e 100644
--- a/Parcel.cpp
+++ b/Parcel.cpp
@@ -186,7 +186,7 @@ inline static status_t finish_flatten_binder(
status_t flatten_binder(const sp<ProcessState>& /*proc*/,
const sp<IBinder>& binder, Parcel* out)
{
- flat_binder_object obj;
+ flat_binder_object obj = {};
if (binder != nullptr) {
BHwBinder *local = binder->localBinder();
@@ -228,7 +228,7 @@ status_t flatten_binder(const sp<ProcessState>& /*proc*/,
status_t flatten_binder(const sp<ProcessState>& /*proc*/,
const wp<IBinder>& binder, Parcel* out)
{
- flat_binder_object obj;
+ flat_binder_object obj = {};
obj.flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
if (binder != nullptr) {
@@ -454,11 +454,11 @@ status_t Parcel::writeInterfaceToken(const char* interface)
bool Parcel::enforceInterface(const char* interface) const
{
const char* str = readCString();
- if (strcmp(str, interface) == 0) {
+ if (str != nullptr && strcmp(str, interface) == 0) {
return true;
} else {
ALOGW("**** enforceInterface() expected '%s' but read '%s'",
- String8(interface).string(), String8(str).string());
+ interface, (str ? str : "<empty string>"));
return false;
}
}
@@ -821,15 +821,16 @@ status_t Parcel::writeEmbeddedBuffer(
LOG_BUFFER("writeEmbeddedBuffer(%p, %zu, parent = (%zu, %zu)) -> %zu",
buffer, length, parent_buffer_handle,
parent_offset, mObjectsSize);
- binder_buffer_object obj;
- obj.hdr.type = BINDER_TYPE_PTR;
- obj.buffer = reinterpret_cast<binder_uintptr_t>(buffer);
- obj.length = length;
- obj.flags = BINDER_BUFFER_FLAG_HAS_PARENT;
if(!validateBufferParent(parent_buffer_handle, parent_offset))
return BAD_VALUE;
- obj.parent = parent_buffer_handle;
- obj.parent_offset = parent_offset;
+ binder_buffer_object obj = {
+ .hdr = { .type = BINDER_TYPE_PTR },
+ .buffer = reinterpret_cast<binder_uintptr_t>(buffer),
+ .length = length,
+ .flags = BINDER_BUFFER_FLAG_HAS_PARENT,
+ .parent = parent_buffer_handle,
+ .parent_offset = parent_offset,
+ };
if (handle != nullptr) {
// We use an index into mObjects as a handle
*handle = mObjectsSize;
@@ -841,11 +842,12 @@ status_t Parcel::writeBuffer(const void *buffer, size_t length, size_t *handle)
{
LOG_BUFFER("writeBuffer(%p, %zu) -> %zu",
buffer, length, mObjectsSize);
- binder_buffer_object obj;
- obj.hdr.type = BINDER_TYPE_PTR;
- obj.buffer = reinterpret_cast<binder_uintptr_t>(buffer);
- obj.length = length;
- obj.flags = 0;
+ binder_buffer_object obj {
+ .hdr = { .type = BINDER_TYPE_PTR },
+ .buffer = reinterpret_cast<binder_uintptr_t>(buffer),
+ .length = length,
+ .flags = 0,
+ };
if (handle != nullptr) {
// We use an index into mObjects as a handle
*handle = mObjectsSize;
@@ -930,7 +932,6 @@ status_t Parcel::writeNativeHandleNoDup(const native_handle_t *handle,
size_t parent_buffer_handle,
size_t parent_offset)
{
- struct binder_fd_array_object fd_array;
size_t buffer_handle;
status_t status = OK;
@@ -955,10 +956,12 @@ status_t Parcel::writeNativeHandleNoDup(const native_handle_t *handle,
return status;
}
- fd_array.hdr.type = BINDER_TYPE_FDA;
- fd_array.num_fds = handle->numFds;
- fd_array.parent = buffer_handle;
- fd_array.parent_offset = offsetof(native_handle_t, data);
+ struct binder_fd_array_object fd_array {
+ .hdr = { .type = BINDER_TYPE_FDA },
+ .num_fds = static_cast<binder_size_t>(handle->numFds),
+ .parent = buffer_handle,
+ .parent_offset = offsetof(native_handle_t, data),
+ };
return writeObject(fd_array);
}
@@ -1204,8 +1207,8 @@ bool Parcel::readBool() const
const char* Parcel::readCString() const
{
- const size_t avail = mDataSize-mDataPos;
- if (avail > 0) {
+ if (mDataPos < mDataSize) {
+ const size_t avail = mDataSize-mDataPos;
const char* str = reinterpret_cast<const char*>(mData+mDataPos);
// is the string's trailing NUL within the parcel's valid bounds?
const char* eos = reinterpret_cast<const char*>(memchr(str, 0, avail));