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

Iterating over a reversed substring can crash

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Standard Library
    • Labels:
    • Environment:

      Tested with Xcode 10.1 (Swift 4.2) and Xcode 10.2 beta 3 (Swift 5).

      Description

      Iterating over a ReversedCollection<String.SubSequence> can crash if the substring starts within an extended grapheme cluster:

      let string = "abc\r\nxyz"
      let idx = string.range(of: "\n")!.lowerBound
      let substring = string[idx...]
      let rev = substring.reversed()
      
      let revString = String(rev) // Fatal error: Out of bounds: index < startIndex
      

       
      The same crash happens with any of the following:

      let arr = Array(rev)
      for c in rev { print(c) }
      print(rev.last!)
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              martin Martin
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: