Skip to content

Commit

Permalink
Fix 'Initialization of 'UnsafePointer<UInt8>' results in a dangling p…
Browse files Browse the repository at this point in the history
…ointer' compiler warning.
  • Loading branch information
tonystone committed Sep 17, 2020
1 parent 174b548 commit a84d652
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions Sources/TraceLog/Internal/Utilities/Streams/RawOutputStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,31 +83,36 @@ extension RawOutputStream: OutputStream {
///
func write(_ bytes: [UInt8]) -> Result<Int, OutputStreamError> {

var buffer = UnsafePointer(bytes)
var length = bytes.count
return bytes.withUnsafeBytes { (bufferPointer) -> Result<Int, OutputStreamError> in
guard var buffer = bufferPointer.baseAddress
else { return .failure(.invalidArgument("byte buffer empty, can not write.")) }

var written: Int = 0
var length = bufferPointer.count

/// Handle partial writes.
///
repeat {
written = self.write(self.fd, buffer, length)
var written: Int = 0

if written == -1 {
if errno == EINTR { /// Always retry if interrupted.
continue
/// Handle partial writes.
///
repeat {
written = self.write(self.fd, buffer, length)

if written == -1 {
if errno == EINTR { /// Always retry if interrupted.
continue
}
return .failure(OutputStreamError.error(for: errno))
}
return .failure(OutputStreamError.error(for: errno))
}
length -= written
buffer += written
length -= written
buffer += written

/// Exit if there are no more bytes (length != 0) or
/// we wrote zero bytes (written != 0)
///
} while (length != 0 && written != 0)
/// Exit if there are no more bytes (length != 0) or
/// we wrote zero bytes (written != 0)
///
} while (length != 0 && written != 0)

return .success(written)

return .success(written)
}
}
}

Expand All @@ -116,7 +121,7 @@ extension RawOutputStream: OutputStream {
internal extension RawOutputStream {

@inline(__always)
func write(_ fd: Int32, _ buffer: UnsafePointer<UInt8>, _ nbytes: Int) -> Int {
func write(_ fd: Int32, _ buffer: UnsafeRawPointer, _ nbytes: Int) -> Int {
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
return Darwin.write(fd, buffer, nbytes)
#elseif os(Linux) || CYGWIN
Expand Down

0 comments on commit a84d652

Please sign in to comment.