Skip to content

Commit

Permalink
Merge pull request #104 from tonystone/write-pointer-fix
Browse files Browse the repository at this point in the history
Fix 'Initialization of 'UnsafePointer<UInt8>' results in a dangling pointer' warning
  • Loading branch information
tonystone committed Oct 8, 2020
2 parents 174b548 + fb97703 commit d382cd5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ matrix:
include:
-
os: linux
dist: trusty
dist: bionic
sudo: required
env:
- BUILD="cmake build"
Expand All @@ -23,7 +23,7 @@ matrix:
- BUILD="cmake build"
-
os: linux
dist: trusty
dist: bionic
sudo: required
env:
- BUILD="swift build"
Expand Down Expand Up @@ -103,9 +103,9 @@ before_install:
sudo apt-get update -y
sudo apt-get -y install clang-3.8 lldb-3.8 libicu-dev
wget https://swift.org/builds/swift-5.0-branch/ubuntu1404/swift-5.0-DEVELOPMENT-SNAPSHOT-2018-12-28-a/swift-5.0-DEVELOPMENT-SNAPSHOT-2018-12-28-a-ubuntu14.04.tar.gz
tar xzvf swift-5.0-DEVELOPMENT-SNAPSHOT-2018-12-28-a-ubuntu14.04.tar.gz
export PATH=$(pwd)/swift-5.0-DEVELOPMENT-SNAPSHOT-2018-12-28-a-ubuntu14.04/usr/bin:$PATH
wget https://swift.org/builds/swift-5.0-release/ubuntu1804/swift-5.0-RELEASE/swift-5.0-RELEASE-ubuntu18.04.tar.gz
tar xzvf swift-5.0-RELEASE-ubuntu18.04.tar.gz
export PATH=$(pwd)/swift-5.0-RELEASE-ubuntu18.04/usr/bin:$PATH
fi
script:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log
All significant changes to this project will be documented in this file.

## [5.0.1](https://github.com/tonystone/tracelog/tree/5.0.1)

#### Fixed
- Fix 'Initialization of 'UnsafePointer<UInt8>' results in a dangling pointer' compiler warning.

## [5.0.0](https://github.com/tonystone/tracelog/tree/5.0.0)

#### Added
Expand Down
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

var written: Int = 0
guard var buffer = bufferPointer.baseAddress
else { return .failure(.invalidArgument("byte buffer empty, can not write.")) }

/// Handle partial writes.
///
repeat {
written = self.write(self.fd, buffer, length)
var length = bufferPointer.count

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

/// Exit if there are no more bytes (length != 0) or
/// we wrote zero bytes (written != 0)
/// Handle partial writes.
///
} while (length != 0 && written != 0)
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))
}
length -= written
buffer += written

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

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
2 changes: 1 addition & 1 deletion TraceLog.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Pod::Spec.new do |s|
s.name = "TraceLog"
s.version = "5.0.0"
s.version = "5.0.1"
s.summary = "Dead Simple: logging the way it's meant to be!"
s.description = <<-DESC
TraceLog is a configurable debug logging system. It is unique in that it's configured
Expand Down

0 comments on commit d382cd5

Please sign in to comment.