Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
> Make sure that ScratchBuffer::Allocate() always return 8-byte aligned addresses.
>
> BUG=None
> TEST=None
>
> Review URL: https://codereview.chromium.org/265403003
TBR=yzshen@chromium.org
Review URL: https://codereview.chromium.org/265823012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268434 0039d316-1c4b-4281-b951-d872f2087c98
CrOS-Libchrome-Original-Commit: c178a234601bc745351061294b9a66690cc9d2cb
diff --git a/mojo/public/cpp/bindings/lib/scratch_buffer.cc b/mojo/public/cpp/bindings/lib/scratch_buffer.cc
index dee048f..9d23dcb 100644
--- a/mojo/public/cpp/bindings/lib/scratch_buffer.cc
+++ b/mojo/public/cpp/bindings/lib/scratch_buffer.cc
@@ -80,12 +80,11 @@
return false;
// Ensure segment buffer is aligned.
- size_t padded_segment_size = internal::Align(sizeof(Segment));
- Segment* segment = static_cast<Segment*>(
- malloc(padded_segment_size + delta));
+ size_t segment_size = internal::Align(sizeof(Segment)) + delta;
+ Segment* segment = static_cast<Segment*>(malloc(segment_size));
if (segment) {
segment->next = overflow_;
- segment->cursor = reinterpret_cast<char*>(segment) + padded_segment_size;
+ segment->cursor = reinterpret_cast<char*>(segment + 1);
segment->end = segment->cursor + delta;
overflow_ = segment;
return true;
diff --git a/mojo/public/cpp/bindings/tests/buffer_unittest.cc b/mojo/public/cpp/bindings/tests/buffer_unittest.cc
index 1487ced..7ef7520 100644
--- a/mojo/public/cpp/bindings/tests/buffer_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/buffer_unittest.cc
@@ -53,23 +53,6 @@
EXPECT_TRUE(!overflow);
}
-TEST(ScratchBufferTest, Alignment) {
- Environment env;
-
- internal::ScratchBuffer buf;
- // Test that small allocations on the stack are aligned properly.
- void* small = buf.Allocate(1);
- EXPECT_EQ(0, reinterpret_cast<ptrdiff_t>(small) % 8);
- small = buf.Allocate(2);
- EXPECT_EQ(0, reinterpret_cast<ptrdiff_t>(small) % 8);
-
- // Test that large allocations on the heap are aligned properly.
- void* large = buf.Allocate(10*1024);
- EXPECT_EQ(0, reinterpret_cast<ptrdiff_t>(large) % 8);
- large = buf.Allocate(100*1024);
- EXPECT_EQ(0, reinterpret_cast<ptrdiff_t>(large) % 8);
-}
-
// Tests that Buffer::current() returns the correct value.
TEST(ScratchBufferTest, Stacked) {
Environment env;