<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I see the issue.. the latest version traps (appropriately so).<div class=""><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class=""><span style="color: #fd4384" class="">let</span> str = <span style="color: #eedb04" class="">String</span>(bytes: <span style="color: #76e0f2" class="">data</span>[<span style="color: #f57fff" class="">0</span>..&lt;<span style="color: #f57fff" class="">2</span>], encoding: .<span style="color: #76e0f2" class="">utf8</span>)!</div><div class=""><div><br class=""></div><div>The sub-range of the slice you have is incorrectly indexed. Try this out (I am presuming this is what you mean):</div><div><br class=""></div><div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(237, 232, 229); background-color: rgb(43, 43, 43);" class=""><span style="color: #fd4384" class="">let</span> str = <span style="color: #eedb04" class="">String</span>(bytes: <span style="color: #76e0f2" class="">data</span>[<span style="color: #76e0f2" class="">data</span>.<span style="color: #76e0f2" class="">startIndex</span>..&lt;(<span style="color: #76e0f2" class="">data</span>.<span style="color: #76e0f2" class="">startIndex</span> + <span style="color: #f57fff" class="">2</span>)], encoding: .<span style="color: #76e0f2" class="">utf8</span>)!</div></div><div><br class=""><blockquote type="cite" class=""><div class="">On Aug 24, 2017, at 11:07 AM, Philippe Hausler &lt;<a href="mailto:phausler@apple.com" class="">phausler@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Is there a radar or <a href="http://bugs.swift.org" class="">bugs.swift.org</a> ticket filed on this?<br class=""><br class="">I presume because of the import this is a Darwin thing and not a linux thing.<br class=""><br class=""><blockquote type="cite" class="">On Aug 24, 2017, at 11:05 AM, Michael Gottesman via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Aug 24, 2017, at 10:47 AM, Ryan Lovelett via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:<br class=""><br class="">I've found what I believe is a bug. Though I'm unclear if the bug is in<br class="">Swift 3.1 or Swift 3.2/4.0. All I can say for sure is the behavior is<br class="">quite drastically different between the two.<br class=""><br class="">For the code below (and attached):<br class=""><br class=""> &nbsp;import Cocoa<br class=""><br class=""> &nbsp;var data = Data(bytes: [0x50, 0x4B, 0x01, 0x02, 0x41, 0x61])<br class=""> &nbsp;data.removeFirst(4)<br class=""> &nbsp;let base64 = data.base64EncodedString()<br class=""> &nbsp;let str = String(bytes: data[0..&lt;2], encoding: .utf8)!<br class=""> &nbsp;print("Base64: \(base64), String: \(str)")<br class=""><br class="">If I compile and run that with the Swift included in Xcode 8.3.3 (e.g.,<br class="">swift ./data-bug.swift) it outputs: Base64: QWE=, String: Aa. Which is<br class="">what I expect.<br class=""><br class="">With the Swift that is included with Xcode 9.0 beta 6 (9M214v) (e.g.,<br class="">swift -swift-version 3 ./data-bug.swift). It performs an illegal<br class="">hardware instruction and crashes. It also does this if I use use the<br class="">version 4 of the compiler.<br class=""><br class="">Is this a bug? If so where is the bug? Was this always meant to not work<br class="">and Swift 3.1 just happened to work or is there now an issue in the<br class="">Swift 3.2 implementation?<br class=""></blockquote><br class="">I have not engaged my brain with the particulars of the rest of the email, but high level question: does this happen without optimization? Or does it happen only with optimization?<br class=""><br class="">Michael<br class=""><br class=""><blockquote type="cite" class="">&lt;data-bug.swift&gt;_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-dev<br class=""></blockquote><br class="">_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-dev<br class=""></blockquote><br class=""></div></div></blockquote></div><br class=""></div></div></div></body></html>