如何解决修复 Inflate 中的 UnsafePointer 警告
我仍然使用很棒的 WebSocketSwift https://github.com/tidwall/SwiftWebSocket 因为这个习惯用法比现在 iOS 中的 websockets 要好得多,
strm.next_in = UnsafePointer<UInt8>(inflateEnd)
结果
Initialization of 'UnsafePointer<UInt8>' results in a dangling pointer
和
Implicit argument conversion from '[UInt8]' to 'UnsafePointer<UInt8>' produces a
pointer valid only for the duration of the call to 'init(_:)'
Use the 'withUnsafeBufferPointer' method on Array in order to explicitly convert
argument to buffer pointer valid for a defined scope
:-(
有没有简单的方法可以消除警告?
https://github.com/tidwall/SwiftWebSocket/blob/master/Source/WebSocket.swift
func inflate(_ bufin : UnsafePointer<UInt8>,length : Int,final : Bool)
throws -> (p : UnsafeMutablePointer<UInt8>,n : Int){
var buf = buffer
var bufsiz = bufferSize
var buflen = 0
for i in 0 ..< 2{
if i == 0 {
strm.avail_in = CUnsignedInt(length)
strm.next_in = UnsafePointer<UInt8>(bufin)
} else {
if !final {
break
}
strm.avail_in = CUnsignedInt(inflateEnd.count)
strm.next_in = UnsafePointer<UInt8>(inflateEnd)
}
while true {
strm.avail_out = CUnsignedInt(bufsiz)
strm.next_out = buf?.assumingMemoryBound(to: UInt8.self)
_ = inflateG(&strm,flush: 0)
let have = bufsiz - Int(strm.avail_out)
bufsiz -= have
buflen += have
if strm.avail_out != 0{
break
}
if bufsiz == 0 {
bufferSize *= 2
let nbuf = realloc(buffer,bufferSize)
if nbuf == nil {
throw WebSocketError.payloadError("memory")
}
buffer = nbuf
buf = buffer?.advanced(by: Int(buflen))
bufsiz = bufferSize - buflen
}
}
}
return (buffer!.assumingMemoryBound(to: UInt8.self),buflen)
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。