diff --git a/stdlib/public/core/UnsafeRawBufferPointer.swift.gyb b/stdlib/public/core/UnsafeRawBufferPointer.swift.gyb index a73c85e2e8ad2..25f84e75d78c9 100644 --- a/stdlib/public/core/UnsafeRawBufferPointer.swift.gyb +++ b/stdlib/public/core/UnsafeRawBufferPointer.swift.gyb @@ -845,7 +845,7 @@ extension Unsafe${Mutable}RawBufferPointer { "buffer base address must be properly aligned to access C.Element" ) _precondition( - $0.count * MemoryLayout.stride < self.count, + $0.count * MemoryLayout.stride <= self.count, "buffer cannot contain every element from source collection." ) let start = baseAddress?.initializeMemory( diff --git a/validation-test/stdlib/UnsafeBufferPointer.swift.gyb b/validation-test/stdlib/UnsafeBufferPointer.swift.gyb index 0b9e6db317de4..ada9a8f6277d2 100644 --- a/validation-test/stdlib/UnsafeBufferPointer.swift.gyb +++ b/validation-test/stdlib/UnsafeBufferPointer.swift.gyb @@ -1264,6 +1264,9 @@ UnsafeMutableRawBufferPointerTestSuite.test("UMRBP.initializeMemory.collection.o alignment: MemoryLayout.alignment ) defer { b.deallocate() } + let i = b.initializeMemory(as: Int.self, fromContentsOf: s.dropLast()) + i.deinitialize() + expectCrash { let i = b.initializeMemory(as: Int.self, fromContentsOf: s) i.deinitialize()