From 641bda6f9c896726887f52bfc1f5a2e0799e0d94 Mon Sep 17 00:00:00 2001 From: "andrew@webrtc.org" Date: Mon, 8 Sep 2014 23:11:44 +0000 Subject: [PATCH] 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 --- webrtc/modules/audio_processing/common.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/webrtc/modules/audio_processing/common.h b/webrtc/modules/audio_processing/common.h index c1bae896ce..98c624127c 100644 --- a/webrtc/modules/audio_processing/common.h +++ b/webrtc/modules/audio_processing/common.h @@ -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_]; }