Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1006)

Unified Diff: third_party/WebKit/Source/platform/graphics/ContiguousContainer.h

Issue 2122573002: Correct alignment in ContiguousContainer::appendByMoving() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 0u Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/ContiguousContainer.h
diff --git a/third_party/WebKit/Source/platform/graphics/ContiguousContainer.h b/third_party/WebKit/Source/platform/graphics/ContiguousContainer.h
index a50431becefb31c3ab4a231c74212f66ea67bf33..95d21b2d4cd5c06733100281e20f2890dee8363e 100644
--- a/third_party/WebKit/Source/platform/graphics/ContiguousContainer.h
+++ b/third_party/WebKit/Source/platform/graphics/ContiguousContainer.h
@@ -166,8 +166,7 @@ public:
"Must use subclass of BaseElementType.");
static_assert(alignment % WTF_ALIGN_OF(DerivedElementType) == 0,
"Derived type requires stronger alignment.");
- size_t allocSize = align(sizeof(DerivedElementType));
- return *new (allocate(allocSize)) DerivedElementType(std::forward<Args>(args)...);
+ return *new (alignedAllocate(sizeof(DerivedElementType))) DerivedElementType(std::forward<Args>(args)...);
}
void removeLast()
@@ -193,24 +192,26 @@ public:
BaseElementType& appendByMoving(BaseElementType& item, size_t size)
{
ASSERT(size >= sizeof(BaseElementType));
- void* newItem = allocate(size);
+ void* newItem = alignedAllocate(size);
memcpy(newItem, static_cast<void*>(&item), size);
new (&item) BaseElementType;
return *static_cast<BaseElementType*>(newItem);
}
private:
- void* allocate(size_t objectSize)
+ void* alignedAllocate(size_t size)
{
- return ContiguousContainerBase::allocate(objectSize, WTF_HEAP_PROFILER_TYPE_NAME(BaseElementType));
+ void* result = ContiguousContainerBase::allocate(align(size), WTF_HEAP_PROFILER_TYPE_NAME(BaseElementType));
+ DCHECK_EQ(reinterpret_cast<intptr_t>(result) & (alignment - 1), 0u);
+ return result;
}
static size_t align(size_t size)
{
size_t alignedSize = alignment * ((size + alignment - 1) / alignment);
- ASSERT(alignedSize % alignment == 0);
- ASSERT(alignedSize >= size);
- ASSERT(alignedSize < size + alignment);
+ DCHECK_EQ(alignedSize % alignment, 0u);
+ DCHECK_GE(alignedSize, size);
+ DCHECK_LT(alignedSize, size + alignment);
return alignedSize;
}
};
« no previous file with comments | « cc/base/contiguous_container_unittest.cc ('k') | third_party/WebKit/Source/platform/graphics/ContiguousContainerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698