[swift-dev] Foundation Data Behavior Different (read: crashes) in Swift 3.1 and Swift 3.2

Ryan Lovelett swift-dev at ryan.lovelett.me
Thu Aug 24 12:47:05 CDT 2017

I've found what I believe is a bug. Though I'm unclear if the bug is in
Swift 3.1 or Swift 3.2/4.0. All I can say for sure is the behavior is
quite drastically different between the two.

For the code below (and attached):

    import Cocoa

    var data = Data(bytes: [0x50, 0x4B, 0x01, 0x02, 0x41, 0x61])
    let base64 = data.base64EncodedString()
    let str = String(bytes: data[0..<2], encoding: .utf8)!
    print("Base64: \(base64), String: \(str)")

If I compile and run that with the Swift included in Xcode 8.3.3 (e.g.,
swift ./data-bug.swift) it outputs: Base64: QWE=, String: Aa. Which is
what I expect.

With the Swift that is included with Xcode 9.0 beta 6 (9M214v) (e.g.,
swift -swift-version 3 ./data-bug.swift). It performs an illegal
hardware instruction and crashes. It also does this if I use use the
version 4 of the compiler.

Is this a bug? If so where is the bug? Was this always meant to not work
and Swift 3.1 just happened to work or is there now an issue in the
Swift 3.2 implementation?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: data-bug.swift
Type: application/octet-stream
Size: 233 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20170824/7bf4182f/attachment.obj>

More information about the swift-dev mailing list