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

Jens Persson jens at bitcycle.com
Tue Jun 13 11:42:35 CDT 2017


PS
There are only 17 planes in the (current?) Unicode standard, but I'm
assuming that the CharacterSet.hasMember(inPlane:) shouldn't (randomly?)
crash for UInt8 values other than 0 ... 16?
It also seems strange that it reproducibly crashes or not depending on
which specific font I use.


On Tue, Jun 13, 2017 at 4:00 PM, Jens Persson <jens at bitcycle.com> wrote:

> 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/0246d575/attachment.html>


More information about the swift-users mailing list