summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2019-04-30 17:56:45 -0700
committerSteven Moreland <smoreland@google.com>2019-05-01 16:35:28 +0000
commit97e2d175cf96d460010c437f073ede9053f6c5d9 (patch)
treeb0a7da7006224bd363c6e4b82468745bb3711463 /base
parent5cc1691e717b07d632f30a147404d1bef9716e7a (diff)
downloadlibhidl-97e2d175cf96d460010c437f073ede9053f6c5d9.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
Diffstat (limited to 'base')
-rw-r--r--base/include/hidl/HidlSupport.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/base/include/hidl/HidlSupport.h b/base/include/hidl/HidlSupport.h
index 7812099..93a6251 100644
--- a/base/include/hidl/HidlSupport.h
+++ b/base/include/hidl/HidlSupport.h
@@ -367,7 +367,7 @@ struct hidl_vec {
details::logAlwaysFatal("size can't be negative.");
}
mSize = static_cast<uint32_t>(size);
- mBuffer = new T[mSize];
+ mBuffer = new T[mSize]();
mOwnsBuffer = true;
size_t idx = 0;
@@ -453,7 +453,7 @@ struct hidl_vec {
delete[] mBuffer;
}
mSize = static_cast<uint32_t>(list.size());
- mBuffer = new T[mSize];
+ mBuffer = new T[mSize]();
mOwnsBuffer = true;
size_t idx = 0;
@@ -507,7 +507,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];
@@ -583,7 +583,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];
}