Uncommon / Xit

Mac OS X Git GUI
Other
1.08k stars 50 forks source link

Unsafe pointer warnings #443

Closed Uncommon closed 4 years ago

Uncommon commented 4 years ago

After upgrading to Xcode 11.4 and Swift 5.2, the following warnings now happen:

XTRepository+Staging.swift:129:19: warning: initialization of 'UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>' results in a dangling pointer
      let array = UnsafeMutablePointer<
                  ^~~~~~~~~~~~~~~~~~~~~
XTRepository+Staging.swift:130:62: note: implicit argument conversion from '[UnsafeMutablePointer<CChar>?]' (aka 'Array<Optional<UnsafeMutablePointer<Int8>>>') to 'UnsafePointer<UnsafeMutablePointer<Int8>?>' produces a pointer valid only for the duration of the call to 'init(mutating:)'
                      UnsafeMutablePointer<Int8>?>(mutating: paths)
                                                             ^~~~~
XTRepository+Staging.swift:130:62: note: use the 'withUnsafeBufferPointer' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope
                      UnsafeMutablePointer<Int8>?>(mutating: paths)
                                                             ^
GitExtensions.swift:177:28: warning: initialization of 'UnsafeMutableRawPointer' results in a dangling pointer
    gitCallbacks.payload = UnsafeMutableRawPointer(&mutableCallbacks)
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GitExtensions.swift:177:52: note: implicit argument conversion from 'RemoteCallbacks' to 'UnsafeMutableRawPointer' produces a pointer valid only for the duration of the call to 'init(_:)'
    gitCallbacks.payload = UnsafeMutableRawPointer(&mutableCallbacks)
                                                   ^~~~~~~~~~~~~~~~~
GitExtensions.swift:177:52: note: use 'withUnsafeMutableBytes' in order to explicitly convert argument to buffer pointer valid for a defined scope
    gitCallbacks.payload = UnsafeMutableRawPointer(&mutableCallbacks)
                                                   ^
Uncommon commented 4 years ago

Done in d8dd2f697d1e7d3b7f528d08e1a89a43c4cda995