diff options
author | Steven Moreland <smoreland@google.com> | 2019-04-18 12:54:56 -0700 |
---|---|---|
committer | Steven Moreland <smoreland@google.com> | 2019-04-30 18:11:15 -0700 |
commit | 5cc1691e717b07d632f30a147404d1bef9716e7a (patch) | |
tree | 434e51b1b6697398391a7b6241e4a054407539bc /base/HidlSupport.cpp | |
parent | 874486019fa65856bbd35d173be04b472afa1637 (diff) | |
download | libhidl-5cc1691e717b07d632f30a147404d1bef9716e7a.tar.gz |
Zero-init HIDL core types (all)
hidl_pointer - already zero initialized
hidl_string - now memset to 0
hidl_array - has no pad to initialize, default initialize since we
now expect structs to be default initialized to sane values.
hidl_vec - now memset to 0
hidl_memory - has three aligned(8) items which are always set
hidl_version - unused, but has two uint16_t entries
Zero-init HIDL core types (hidl_handle).
Has 7 padded bits at the end.
Since they are passed across processes.
Bug: 131356202
Test: print out values
Change-Id: I3979232879bb437d17d3a6f6013b53b2951a2138
Merged-In: I56bacf9ca7ac51d73449d11883c6224e214b8773
Merged-In: I8dd52e196e1585028d91d97f00861021c21ec09c
Diffstat (limited to 'base/HidlSupport.cpp')
-rw-r--r-- | base/HidlSupport.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/base/HidlSupport.cpp b/base/HidlSupport.cpp index 58afa69..f97f216 100644 --- a/base/HidlSupport.cpp +++ b/base/HidlSupport.cpp @@ -36,27 +36,28 @@ bool debuggable() { } // namespace details hidl_handle::hidl_handle() { - mHandle = nullptr; - mOwnsHandle = false; + memset(this, 0, sizeof(*this)); + // mHandle = nullptr; + // mOwnsHandle = false; } hidl_handle::~hidl_handle() { freeHandle(); } -hidl_handle::hidl_handle(const native_handle_t *handle) { +hidl_handle::hidl_handle(const native_handle_t* handle) : hidl_handle() { mHandle = handle; mOwnsHandle = false; } // copy constructor. -hidl_handle::hidl_handle(const hidl_handle &other) { +hidl_handle::hidl_handle(const hidl_handle& other) : hidl_handle() { mOwnsHandle = false; *this = other; } // move constructor. -hidl_handle::hidl_handle(hidl_handle&& other) noexcept { +hidl_handle::hidl_handle(hidl_handle&& other) noexcept : hidl_handle() { mOwnsHandle = false; *this = std::move(other); } @@ -137,10 +138,11 @@ void hidl_handle::freeHandle() { static const char *const kEmptyString = ""; -hidl_string::hidl_string() - : mBuffer(kEmptyString), - mSize(0), - mOwnsBuffer(false) { +hidl_string::hidl_string() { + memset(this, 0, sizeof(*this)); + // mSize is zero + // mOwnsBuffer is false + mBuffer = kEmptyString; } hidl_string::~hidl_string() { |