Procházet zdrojové kódy

Merge pull request #445 from kbongort/FixWarnings

Fix build warnings from use of `&` to create a pointer to `buffer`.
Victor Sigler před 6 roky
rodič
revize
425f28bcff
2 změnil soubory, kde provedl 10 přidání a 5 odebrání
  1. 1 0
      CHANGELOG.md
  2. 9 5
      XCode/Sources/Socket+File.swift

+ 1 - 0
CHANGELOG.md

@@ -30,6 +30,7 @@ All notable changes to this project will be documented in this file. Changes not
 - Update `HttpParser` so it percent-encodes the URL components before initializing `URLComponents`. ([#423](https://github.com/httpswift/swifter/pull/423)) by [@nejcvivod](https://github.com/nejcvivod)
 - Update `SwifterTestsHttpParser` with a test for parsing bracketed query strings. ([#423](https://github.com/httpswift/swifter/pull/423)) by [@nejcvivod](https://github.com/nejcvivod)
 - Use `swift_version` CocoaPods DSL. ([#425](https://github.com/httpswift/swifter/pull/425)) by [@dnkoutso](https://github.com/dnkoutso)
+- Fix compiler warnings in Socket+File.swift for iOS, tvOS, and Linux platforms by using `withUnsafeBytes` rather than `&` to get a scoped UnsafeRawPointer.
 
 # [1.4.7] 
 

+ 9 - 5
XCode/Sources/Socket+File.swift

@@ -20,11 +20,15 @@ import Foundation
             }
             var writeCounter = 0
             while writeCounter < readResult {
-                #if os(Linux)
-                    let writeResult = send(target, &buffer + writeCounter, readResult - writeCounter, Int32(MSG_NOSIGNAL))
-                #else
-                    let writeResult = write(target, &buffer + writeCounter, readResult - writeCounter)
-                #endif
+                let writeResult = buffer.withUnsafeBytes { (ptr) -> Int in
+                  let start = ptr.baseAddress! + writeCounter
+                  let len = readResult - writeCounter
+                  #if os(Linux)
+                  return send(target, start, len, Int32(MSG_NOSIGNAL))
+                  #else
+                  return write(target, start, len)
+                  #endif
+                }
                 guard writeResult > 0 else {
                     return Int32(writeResult)
                 }