shithub: libvpx

Download patch

ref: 902d63759e53f4b23be7abebabe869db851e2a0d
parent: 4a37e3e2a0b6cfefd8fad181c1345d92e2fea320
author: Johann <johannkoenig@google.com>
date: Tue Jun 6 09:17:07 EDT 2017

buffer.h: add num_elements_

raw_size_ was being incorrectly computed and used

Change-Id: Iade45f69964c567ffb258880f26006a96ae5a30d

--- a/test/buffer.h
+++ b/test/buffer.h
@@ -30,13 +30,13 @@
       : width_(width), height_(height), top_padding_(top_padding),
         left_padding_(left_padding), right_padding_(right_padding),
         bottom_padding_(bottom_padding), padding_value_(0), stride_(0),
-        raw_size_(0), raw_buffer_(NULL) {}
+        raw_size_(0), num_elements_(0), raw_buffer_(NULL) {}
 
   Buffer(size_t width, size_t height, size_t padding)
       : width_(width), height_(height), top_padding_(padding),
         left_padding_(padding), right_padding_(padding),
         bottom_padding_(padding), padding_value_(0), stride_(0), raw_size_(0),
-        raw_buffer_(NULL) {}
+        num_elements_(0), raw_buffer_(NULL) {}
 
   ~Buffer() { delete[] raw_buffer_; }
 
@@ -77,8 +77,9 @@
     EXPECT_GT(width_, 0u);
     EXPECT_GT(height_, 0u);
     stride_ = left_padding_ + width_ + right_padding_;
-    raw_size_ = stride_ * (top_padding_ + height_ + bottom_padding_);
-    raw_buffer_ = new (std::nothrow) T[raw_size_];
+    num_elements_ = stride_ * (top_padding_ + height_ + bottom_padding_);
+    raw_buffer_ = new (std::nothrow) T[num_elements_];
+    raw_size_ = num_elements_ * sizeof(T);
     EXPECT_TRUE(raw_buffer_ != NULL);
     SetPadding(std::numeric_limits<T>::max());
     return !::testing::Test::HasFailure();
@@ -96,6 +97,7 @@
   T padding_value_;
   size_t stride_;
   size_t raw_size_;
+  size_t num_elements_;
   T *raw_buffer_;
 };
 
@@ -209,7 +211,7 @@
   padding_value_ = padding_value;
 
   T *src = raw_buffer_;
-  for (size_t i = 0; i < raw_size_; ++i) {
+  for (size_t i = 0; i < num_elements_; ++i) {
     src[i] = padding_value;
   }
 }