summaryrefslogtreecommitdiff
path: root/retrace
diff options
context:
space:
mode:
authorJose Fonseca <jfonseca@vmware.com>2015-07-20 21:56:00 +0100
committerJose Fonseca <jfonseca@vmware.com>2015-07-21 09:18:45 +0100
commit62682dcee5368fe43284efa4e90f22cb1c88b79e (patch)
tree8291e1c47c06bd436c215d2011635ee51725a3b6 /retrace
parent1e3c0f717bbdc2609fe36f2597a742924186aeb1 (diff)
retrace: Ensure structures are zeroed upon allocation.
As it is hard to ensure that all members are always initialized otherwise, and reproducible behavior is always better.
Diffstat (limited to 'retrace')
-rw-r--r--retrace/retrace.hpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/retrace/retrace.hpp b/retrace/retrace.hpp
index 780c7f2a..c2b06e3f 100644
--- a/retrace/retrace.hpp
+++ b/retrace/retrace.hpp
@@ -67,10 +67,16 @@ public:
* Allocate an array with the same dimensions as the specified value.
*/
inline void *
- allocArray(const trace::Value *value, size_t size) {
+ allocArray(const trace::Value *value, size_t elemSize) {
const trace::Array *array = value->toArray();
if (array) {
- return ::ScopedAllocator::alloc(array->size() * size);
+ size_t numElems = array->size();
+ size_t size = numElems * elemSize;
+ void *ptr = ::ScopedAllocator::alloc(size);
+ if (ptr) {
+ memset(ptr, 0, size);
+ }
+ return ptr;
}
const trace::Null *null = value->toNull();
if (null) {