Skip to content

placement new does not return aligned data in/near GetStackingAllocator() #73418

@RobertHenry6bev

Description

@RobertHenry6bev

Description

bmtParent->pSlotTable = new (GetStackingAllocator())
(and many other places) invokes a placement new on a call to method GetStackingAllocator(), which calls UnsafeAllocNoThrow, which returns the placed new. The placed new is not aligned to 0 mod 16.

UnsafeAllocNoThrow() is a chamber of horrors.

  • It returns a cast -1 when the number of things requested is 0, which happens. (Perhaps this in itself is a bug.)
  • -1 is not aligned to 0 mod 16. It also has the magic number "7" in the code, which should really be the desired alignment (a power of 2) -1. (The code now assumes the caller is happy with alignment of 8 bytes.)

Reproduction Steps

compile with clang-14 -g -O0 -fsanitize=undefined; run the code,; and wait for runtime errors.

Expected behavior

no runtime errors

Actual behavior

runtime errors from ubsan

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

cc / @AaronRobinsonMSFT

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions