Skip to content

Commit 1b4d116

Browse files
authored
Merge pull request swiftlang#69426 from glessard/rdar117516235
[5.10] Fix precondition in UMRBP.initialize(as:fromContentsOf:)
2 parents 8048549 + dace05b commit 1b4d116

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

stdlib/public/core/UnsafeRawBufferPointer.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ extension Unsafe${Mutable}RawBufferPointer {
845845
"buffer base address must be properly aligned to access C.Element"
846846
)
847847
_precondition(
848-
$0.count * MemoryLayout<C.Element>.stride < self.count,
848+
$0.count * MemoryLayout<C.Element>.stride <= self.count,
849849
"buffer cannot contain every element from source collection."
850850
)
851851
let start = baseAddress?.initializeMemory(

validation-test/stdlib/UnsafeBufferPointer.swift.gyb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,9 @@ UnsafeMutableRawBufferPointerTestSuite.test("UMRBP.initializeMemory.collection.o
12641264
alignment: MemoryLayout<Int>.alignment
12651265
)
12661266
defer { b.deallocate() }
1267+
let i = b.initializeMemory(as: Int.self, fromContentsOf: s.dropLast())
1268+
i.deinitialize()
1269+
12671270
expectCrash {
12681271
let i = b.initializeMemory(as: Int.self, fromContentsOf: s)
12691272
i.deinitialize()

0 commit comments

Comments
 (0)