Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-7851] _DataStorage's enumerateBytes method should use bindMemory instead of assumingMemoryBound(to:) #3686

Closed
hamishknight opened this issue Jun 2, 2018 · 2 comments

Comments

@hamishknight
Copy link

Previous ID SR-7851
Radar rdar://problem/40823964
Original Reporter @hamishknight
Type Bug
Status Closed
Resolution Won't Do
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: bda013309a6dcfbc21532411d9cfdc6f

relates to:

  • SR-7726 Data.withUnsafe(Mutable)Bytes should use bindMemory(to:) instead of assumingMemoryBound(to:)

Issue Description:

Currently the implementation of _DataStorage's enumerateBytes method uses assumingMemoryBound(to:) in order to obtain a typed pointer to the underlying memory – however this can produce undefined behaviour if the underlying memory is bound to a type unrelated to UInt8.

Instead, we should probably use bindMemory(to:) in order to avoid this potential source of UB (at least until the API for enumerateBytes changes to work with a UnsafeRawBufferPointer instead of a UnsafeBufferPointer<UInt8>).

See https://forums.swift.org/t/how-to-use-data-withunsafebytes-in-a-well-defined-manner/12811 for more context.

@atrick
Copy link
Member

atrick commented Jun 5, 2018

@swift-ci create

@atrick
Copy link
Member

atrick commented Apr 8, 2019

This API was deprecated in Swift 5.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants