From 0209e95cc2625a445c1cb6c4213d2182e5c832d7 Mon Sep 17 00:00:00 2001 From: mtklein Date: Thu, 28 Aug 2014 14:10:05 -0700 Subject: Align all SkRecord::alloc() calls up to at least a pointer size. This should make the LSAN bots able to see all our pointers. BUG=skia: R=reed@google.com, robertphillips@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/517073002 --- tests/RecordTest.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests/RecordTest.cpp') diff --git a/tests/RecordTest.cpp b/tests/RecordTest.cpp index 2240ae9858..2a0e615516 100644 --- a/tests/RecordTest.cpp +++ b/tests/RecordTest.cpp @@ -78,3 +78,28 @@ DEF_TEST(Record, r) { #undef APPEND +template +static bool is_aligned(const T* p) { + return (((uintptr_t)p) & (sizeof(T) - 1)) == 0; +} + +DEF_TEST(Record_Alignment, r) { + SkRecord record; + + // Of course a byte's always aligned. + REPORTER_ASSERT(r, is_aligned(record.alloc())); + + // (If packed tightly, the rest below here would be off by one.) + + // It happens that the first implementation always aligned to 4 bytes, + // so these two were always correct. + REPORTER_ASSERT(r, is_aligned(record.alloc())); + REPORTER_ASSERT(r, is_aligned(record.alloc())); + + // These two are regression tests (void* only on 64-bit machines). + REPORTER_ASSERT(r, is_aligned(record.alloc())); + REPORTER_ASSERT(r, is_aligned(record.alloc())); + + // We're not testing beyond sizeof(void*), which is where the current implementation will break. +} + -- cgit v1.2.3