swiftlang / swift-corelibs-foundation

The Foundation Project, providing core utilities, internationalization, and OS independence
swift.org
Apache License 2.0
5.28k stars 1.13k forks source link

[SR-4711] Foundation.Data slice is off by one when start is non-zero #4527

Closed swift-ci closed 6 years ago

swift-ci commented 7 years ago
Previous ID SR-4711
Radar None
Original Reporter lauriebr (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment Ubuntu 16.04 LTS Swift 3.1.1
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Foundation | |Labels | Bug, Linux | |Assignee | None | |Priority | Medium | md5: 96839e079b4e6a5a20372cc44f80fb2f

Issue Description:

Summary:
When taking a slice from an instance of Foundation.Data and the left side range is not 0, the slice is off by 1 on Ubuntu 16.04 LTS

Steps to Reproduce:
Download and install swift 3.1.1 per swift.org instructions
In a command prompt:
mkdir DataTest
cd DataTest
swift package init --type executable
vi Sources/main.swift

main.swift code--------------------------------
import Foundation

var test = Data([81, 0, 0, 0, 14])
var test2 = test[1...4]
test2.map({ print($0) })


:wq out of vi
swift build
.build/debug/DataTest

Expected Results:
expected console output
0
0
0
14

Actual Results:
actual console output
0
0
14
127

swift-ci commented 6 years ago

Comment by Yura Samsoniuk (JIRA)

Docker image swift:4.2.
Prints:

0
0
0
14