From 8898cad80fd8ab6864e25918ddd1664ec5670008 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 2 Oct 2019 10:31:11 -0400 Subject: [PATCH 1/2] Initialize data buffer. This CL does an explicit memset of the data buffer to make sure it is initialized with zeros. --- src/buffer.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/buffer.cc b/src/buffer.cc index fd4e1c6cb..6a264691e 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -239,6 +239,15 @@ Result Buffer::SetDataWithOffset(const std::vector& data, // this maybe the first time data is set into the buffer. bytes_.resize(GetSizeInBytes()); + // Set the new memory to zero to be on the safe side. + int32_t new_space = static_cast( + (static_cast(data.size()) / format_->InputNeededPerElement()) * + format_->SizeInBytes()); + assert(static_cast(new_space) + offset <= GetSizeInBytes()); + + if (new_space > 0) + memset(bytes_.data() + offset, new_space, sizeof(uint8_t)); + if (data.size() > (ElementCount() * format_->InputNeededPerElement())) return Result("Mismatched number of items in buffer"); From dac8519b0e876af9980f90577abffd47f448a77d Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 3 Oct 2019 09:12:59 -0400 Subject: [PATCH 2/2] Fixup params --- src/buffer.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index 6a264691e..5a4250883 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -240,13 +240,13 @@ Result Buffer::SetDataWithOffset(const std::vector& data, bytes_.resize(GetSizeInBytes()); // Set the new memory to zero to be on the safe side. - int32_t new_space = static_cast( + uint32_t new_space = (static_cast(data.size()) / format_->InputNeededPerElement()) * - format_->SizeInBytes()); - assert(static_cast(new_space) + offset <= GetSizeInBytes()); + format_->SizeInBytes(); + assert(new_space + offset <= GetSizeInBytes()); if (new_space > 0) - memset(bytes_.data() + offset, new_space, sizeof(uint8_t)); + memset(bytes_.data() + offset, 0, new_space); if (data.size() > (ElementCount() * format_->InputNeededPerElement())) return Result("Mismatched number of items in buffer");