diff --git a/standalone/combined.h b/standalone/combined.h index 15a199ae034..f9ed36581f8 100644 --- a/standalone/combined.h +++ b/standalone/combined.h @@ -1052,6 +1052,10 @@ class Allocator { void *Block, const uptr UserPtr, const uptr SizeOrUnusedBytes, const FillContentsMode FillContents) { + // Compute the default pointer before adding the header tag + const uptr DefaultAlignedPtr = + reinterpret_cast(Block) + Chunk::getHeaderSize(); + Block = addHeaderTag(Block); // Only do content fill when it's from primary allocator because secondary // allocator has filled the content. @@ -1064,8 +1068,6 @@ class Allocator { Chunk::UnpackedHeader Header = {}; - const uptr DefaultAlignedPtr = - reinterpret_cast(Block) + Chunk::getHeaderSize(); if (UNLIKELY(DefaultAlignedPtr != UserPtr)) { const uptr Offset = UserPtr - DefaultAlignedPtr; DCHECK_GE(Offset, 2 * sizeof(u32)); @@ -1096,6 +1098,10 @@ class Allocator { const Options Options = Primary.Options.load(); DCHECK(useMemoryTagging(Options)); + // Compute the default pointer before adding the header tag + const uptr DefaultAlignedPtr = + reinterpret_cast(Block) + Chunk::getHeaderSize(); + void *Ptr = reinterpret_cast(UserPtr); void *TaggedPtr = Ptr; @@ -1194,8 +1200,6 @@ class Allocator { Chunk::UnpackedHeader Header = {}; - const uptr DefaultAlignedPtr = - reinterpret_cast(Block) + Chunk::getHeaderSize(); if (UNLIKELY(DefaultAlignedPtr != UserPtr)) { const uptr Offset = UserPtr - DefaultAlignedPtr; DCHECK_GE(Offset, 2 * sizeof(u32));