Uploaded image for project: 'Swift'
  1. Swift
  2. SR-2790

Reject UnsafePointer initialization via implicit pointer conversion.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Labels:
      None
    • Environment:

      macOS: 10.11.6 (15G1004)
      Swift: 3.0 (swiftlang-800.0.46.2 clang-800.0.38)

      Description

      It seems perhaps that putting an UnsafePointer into an array somehow mangles the data. It also happens with UnsafeMutablePointer(mutating: ). I'm not sure whats going on so I'll just show an example.

      I would expect the following code to print "swift", but instead it prints nonsense, generally two or three characters though: examples outputs include "P�", " -", "`[".

      import Foundation
      
      var strings:[UnsafePointer<Int8>] = []
      strings.append(UnsafePointer<Int8>("swift".cString(using:String.Encoding.ascii))!)
      print(String(cString:strings[0]))
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              originaluser2 Hamish Knight
              Reporter:
              sclukey Steven Clukey
              Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: