Initialize ChannelBuffer's memory to avoid uninitialized reads.

Removed the zero out memset in this change:
https://review.webrtc.org/24469004/

assuming it was unneeded. Dr. Memory taught me that assupmtion was
invalid. linux_memcheck try runs might have caught this, if they
weren't flaking out on unrelated stuff.

TBR=claguna@google.com

Review URL: https://webrtc-codereview.appspot.com/28429004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7113 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
andrew@webrtc.org
2014-09-08 23:11:44 +00:00
parent 8b0b21161a
commit 641bda6f9c

View File

@ -43,7 +43,7 @@ class ChannelBuffer {
channels_(new T*[num_channels]),
samples_per_channel_(samples_per_channel),
num_channels_(num_channels) {
SetChannelPtrs();
Initialize();
}
ChannelBuffer(const T* data, int samples_per_channel, int num_channels)
@ -51,7 +51,7 @@ class ChannelBuffer {
channels_(new T*[num_channels]),
samples_per_channel_(samples_per_channel),
num_channels_(num_channels) {
SetChannelPtrs();
Initialize();
memcpy(data_.get(), data, length() * sizeof(T));
}
@ -61,7 +61,7 @@ class ChannelBuffer {
channels_(new T*[num_channels]),
samples_per_channel_(samples_per_channel),
num_channels_(num_channels) {
SetChannelPtrs();
Initialize();
for (int i = 0; i < num_channels_; ++i)
CopyFrom(channels[i], i);
}
@ -94,7 +94,8 @@ class ChannelBuffer {
int length() const { return samples_per_channel_ * num_channels_; }
private:
void SetChannelPtrs() {
void Initialize() {
memset(data_.get(), 0, sizeof(T) * length());
for (int i = 0; i < num_channels_; ++i)
channels_[i] = &data_[i * samples_per_channel_];
}