Request to cleanup some uses of bindMemory and assumingMemoryBound
Closed this issue · 1 comments
atrick commented
Doing a random github search I found some potential misuses of the bindMemory API
which should be written (safely) as
_ = bytes.load(fromByteOffset: position, as: UInt8.self)
let payloadBytes = UnsafeRawBufferPointer(bytes, capacity: length)
_ = payloadBytes[i]
And of assumingMemoryBound(to:)
which should be written as:
let bytes = UnsafeRawBufferPointer(buffer.bytes, capacity: buffer.length)
private mutating func parseOpCode(bytes: UnsafeRawBufferPointer, from: Int) -> (WebSocketError?, Int) {
^^^^^^^^^^^^^^^^^^^^^^
bytes.load(fromByteOffset: from+1, as: UInt16.self)
Same thing here:
And here:
ianpartridge commented
Thanks!