summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2019-04-30 17:56:45 -0700
committerSteven Moreland <smoreland@google.com>2019-05-08 18:40:34 +0000
commit6e8d69c766e550b06028146c1d4888b464f175a6 (patch)
tree0fca155c54905c4cb751bbdaf6a4725f1f4444bd
parent0cea857b15b40a0de345925da0287e9d1026180d (diff)
downloadlibhidl-6e8d69c766e550b06028146c1d4888b464f175a6.tar.gz
Zero-initialize hidl_vec data
Bug: 131356202 Test: manually check padding in structs allocated in these arrays Test: libhwbinder_benchmark, well within variance (this test allocates arrays). Before: --------------------------------------------------------------------- Benchmark Time CPU Iterations --------------------------------------------------------------------- BM_sendVec_binderize/4 34935 ns 15081 ns 36091 BM_sendVec_binderize/8 39140 ns 16846 ns 38865 BM_sendVec_binderize/16 36495 ns 15833 ns 44182 BM_sendVec_binderize/32 39785 ns 17182 ns 38870 BM_sendVec_binderize/64 35647 ns 15466 ns 38215 BM_sendVec_binderize/128 39145 ns 16873 ns 44856 BM_sendVec_binderize/256 38836 ns 16801 ns 41596 BM_sendVec_binderize/512 41014 ns 17831 ns 40161 BM_sendVec_binderize/1024 37534 ns 16270 ns 41794 BM_sendVec_binderize/2048 37662 ns 16471 ns 42331 BM_sendVec_binderize/4096 38551 ns 16809 ns 35635 BM_sendVec_binderize/8192 36139 ns 15865 ns 42185 BM_sendVec_binderize/16384 51743 ns 22600 ns 31556 BM_sendVec_binderize/32768 46644 ns 20616 ns 30220 BM_sendVec_binderize/65536 68763 ns 30412 ns 25429 After: --------------------------------------------------------------------- Benchmark Time CPU Iterations --------------------------------------------------------------------- BM_sendVec_binderize/4 39549 ns 17214 ns 35193 BM_sendVec_binderize/8 38786 ns 16822 ns 37402 BM_sendVec_binderize/16 37787 ns 16492 ns 37100 BM_sendVec_binderize/32 40796 ns 17567 ns 36399 BM_sendVec_binderize/64 41024 ns 17797 ns 45328 BM_sendVec_binderize/128 36169 ns 15707 ns 39602 BM_sendVec_binderize/256 37136 ns 16094 ns 47081 BM_sendVec_binderize/512 37998 ns 16443 ns 48487 BM_sendVec_binderize/1024 35190 ns 15318 ns 40091 BM_sendVec_binderize/2048 37665 ns 16399 ns 39498 BM_sendVec_binderize/4096 45963 ns 19877 ns 36884 BM_sendVec_binderize/8192 40075 ns 17620 ns 34013 BM_sendVec_binderize/16384 46224 ns 20315 ns 34384 BM_sendVec_binderize/32768 49775 ns 21994 ns 35334 BM_sendVec_binderize/65536 60181 ns 27238 ns 22205 Change-Id: Ica6c55e7346b9e1ba91192472e2b229cb786802c Merged-In: Ica6c55e7346b9e1ba91192472e2b229cb786802c
-rw-r--r--base/include/hidl/HidlSupport.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/base/include/hidl/HidlSupport.h b/base/include/hidl/HidlSupport.h
index ad1293f..d636545 100644
--- a/base/include/hidl/HidlSupport.h
+++ b/base/include/hidl/HidlSupport.h
@@ -306,7 +306,7 @@ struct hidl_vec {
details::logAlwaysFatal("hidl_vec can't hold more than 2^32 elements.");
}
mSize = static_cast<uint32_t>(list.size());
- mBuffer = new T[mSize];
+ mBuffer = new T[mSize]();
mOwnsBuffer = true;
size_t idx = 0;
@@ -431,7 +431,7 @@ struct hidl_vec {
if (size > UINT32_MAX) {
details::logAlwaysFatal("hidl_vec can't hold more than 2^32 elements.");
}
- T *newBuffer = new T[size];
+ T* newBuffer = new T[size]();
for (size_t i = 0; i < std::min(static_cast<uint32_t>(size), mSize); ++i) {
newBuffer[i] = mBuffer[i];
@@ -507,7 +507,7 @@ private:
mSize = static_cast<uint32_t>(size);
mOwnsBuffer = true;
if (mSize > 0) {
- mBuffer = new T[size];
+ mBuffer = new T[size]();
for (size_t i = 0; i < size; ++i) {
mBuffer[i] = data[i];
}