From a84d6521c5666904ff9fbf51cac5bb31d37cc5c7 Mon Sep 17 00:00:00 2001 From: Tony Stone Date: Thu, 17 Sep 2020 11:02:02 -0500 Subject: [PATCH 1/5] Fix 'Initialization of 'UnsafePointer' results in a dangling pointer' compiler warning. --- .../Utilities/Streams/RawOutputStream.swift | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/Sources/TraceLog/Internal/Utilities/Streams/RawOutputStream.swift b/Sources/TraceLog/Internal/Utilities/Streams/RawOutputStream.swift index fa578ef1..c646463f 100644 --- a/Sources/TraceLog/Internal/Utilities/Streams/RawOutputStream.swift +++ b/Sources/TraceLog/Internal/Utilities/Streams/RawOutputStream.swift @@ -83,31 +83,36 @@ extension RawOutputStream: OutputStream { /// func write(_ bytes: [UInt8]) -> Result { - var buffer = UnsafePointer(bytes) - var length = bytes.count + return bytes.withUnsafeBytes { (bufferPointer) -> Result 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) + } } } @@ -116,7 +121,7 @@ extension RawOutputStream: OutputStream { internal extension RawOutputStream { @inline(__always) - func write(_ fd: Int32, _ buffer: UnsafePointer, _ 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 From 408b734e9ee13ee9191298dbe1aee222ef38c379 Mon Sep 17 00:00:00 2001 From: Tony Stone Date: Thu, 17 Sep 2020 11:35:04 -0500 Subject: [PATCH 2/5] Update CHANGELOG and podpsec with latest release information, 5.0.1. --- CHANGELOG.md | 5 +++++ TraceLog.podspec | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 064925b1..66c1f095 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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' results in a dangling pointer' compiler warning. + ## [5.0.0](https://github.com/tonystone/tracelog/tree/5.0.0) #### Added diff --git a/TraceLog.podspec b/TraceLog.podspec index a308bc14..ad4bc11f 100644 --- a/TraceLog.podspec +++ b/TraceLog.podspec @@ -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 From dbc886e98627c424d29403bd14bd4fc77ddceb36 Mon Sep 17 00:00:00 2001 From: Tony Stone Date: Fri, 18 Sep 2020 11:58:19 -0500 Subject: [PATCH 3/5] Add space for proper formatting of code. --- .../TraceLog/Internal/Utilities/Streams/RawOutputStream.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/TraceLog/Internal/Utilities/Streams/RawOutputStream.swift b/Sources/TraceLog/Internal/Utilities/Streams/RawOutputStream.swift index c646463f..86214cb5 100644 --- a/Sources/TraceLog/Internal/Utilities/Streams/RawOutputStream.swift +++ b/Sources/TraceLog/Internal/Utilities/Streams/RawOutputStream.swift @@ -84,6 +84,7 @@ extension RawOutputStream: OutputStream { func write(_ bytes: [UInt8]) -> Result { return bytes.withUnsafeBytes { (bufferPointer) -> Result in + guard var buffer = bufferPointer.baseAddress else { return .failure(.invalidArgument("byte buffer empty, can not write.")) } From 32a8acb21b0db1d31f079b2b2c34c0c060edc4b8 Mon Sep 17 00:00:00 2001 From: Tony Stone Date: Fri, 18 Sep 2020 11:59:54 -0500 Subject: [PATCH 4/5] The swift project no longer supports Linux `trusty`, upgrading to `bionic`. --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index a6837e85..6818ce26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ matrix: include: - os: linux - dist: trusty + dist: bionic sudo: required env: - BUILD="cmake build" @@ -23,7 +23,7 @@ matrix: - BUILD="cmake build" - os: linux - dist: trusty + dist: bionic sudo: required env: - BUILD="swift build" @@ -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: From fb9770322bb53067318137af69ff33328b5671ee Mon Sep 17 00:00:00 2001 From: Tony Stone Date: Mon, 21 Sep 2020 09:48:53 -0500 Subject: [PATCH 5/5] Misc formatting of code. --- .../TraceLog/Internal/Utilities/Streams/RawOutputStream.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/TraceLog/Internal/Utilities/Streams/RawOutputStream.swift b/Sources/TraceLog/Internal/Utilities/Streams/RawOutputStream.swift index 86214cb5..4cda02b5 100644 --- a/Sources/TraceLog/Internal/Utilities/Streams/RawOutputStream.swift +++ b/Sources/TraceLog/Internal/Utilities/Streams/RawOutputStream.swift @@ -84,7 +84,7 @@ extension RawOutputStream: OutputStream { func write(_ bytes: [UInt8]) -> Result { return bytes.withUnsafeBytes { (bufferPointer) -> Result in - + guard var buffer = bufferPointer.baseAddress else { return .failure(.invalidArgument("byte buffer empty, can not write.")) } @@ -111,7 +111,6 @@ extension RawOutputStream: OutputStream { /// } while (length != 0 && written != 0) - return .success(written) } }