[swift-users] Runtime crash caused by (NS)CharacterSet.hasMember?

Jens Persson jens at bitcycle.com
Tue Jun 13 09:00:25 CDT 2017


The below program demonstrates a possible bug that I encountered.
Can anyone else reproduce my results (as explained in the comments)?
If so, is it a Swift or Cocoa bug (I haven't tried it in Objective C)?

import AppKit

extension NSFont {
    var planesWithMembers: [UInt8] {
        return (UInt8(0) ... UInt8(255)).filter {
            // The follwing line will crash (EXC_BAD_ACCESS) for some fonts:
            coveredCharacterSet.hasMember(inPlane: $0)
            // I have tested it with Xcode 8.3.3 and Xcode 9 beta 1, both
            // Swift 3 and 4, and they all reproduce the crash.
            // macOS 10.12.5
        }
    }
}

// Examples that will not cause the crash:
// let fontName = "AlBayan"
// let fontName = "AppleBraille"
// let fontName = "Chalkboard"
// let fontName = "Helvetica"
// let fontName = "Zapfino"

// Examples that will cause the crash:
// let fontName = "AppleColorEmoji"
// let fontName = "AppleSymbols"
let fontName = "Baskerville"
// let fontName = "Geneva"
// let fontName = "SnellRoundhand"

let font = NSFont(name: fontName, size: 12)!
let result = font.planesWithMembers
print("Planes that contains members:", result)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170613/c3a98831/attachment.html>


More information about the swift-users mailing list