Skip to content

[SR-10689] DataProtocol.firstRange/lastRange does not work properly #3417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
swift-ci opened this issue May 15, 2019 · 6 comments
Closed

[SR-10689] DataProtocol.firstRange/lastRange does not work properly #3417

swift-ci opened this issue May 15, 2019 · 6 comments
Assignees

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-10689
Radar rdar://79092495
Original Reporter nanasi (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 10.2

Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3)
Target: x86_64-apple-darwin18.5.0

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee @YOCKOW
Priority Medium

md5: 9dd008936346109659158a2dac5cae0c

is duplicated by:

  • SR-14792 Linux: Segmentation Fault with Data's lastRangeOf

Issue Description:

case 1

import Foundation

let data = Data([1, 2, 3])
print(data.range(of: Data([1, 2, 3])))       // print 0..<3
print(data.firstRange(of: Data([1, 2, 3])))  // print nil

case 2

import Foundation

let data = Data([1, 2, 3])
let range = data.startIndex..<data.endIndex
print(data.range(of: Data([1]), options: .backwards, in: range))  // print 0..<1
print(data.lastRange(of: Data([1]), in: range))                   // causes EXC_BAD_INSTRUCTION

case 2 console:

error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.

* thread #&#8203;1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
  * frame #&#8203;0: 0x000000011b7092ad libswiftFoundation.dylib`Foundation.Data.subscript.read : (Swift.Int) -> Swift.UInt8 + 317
    frame #&#8203;1: 0x00000001052d5117 libswiftCore.dylib`dispatch thunk of Swift.Collection.subscript.read : (A.Index) -> A.Element + 7
    frame #&#8203;2: 0x000000011b6f9d5f libswiftFoundation.dylib`(extension in Foundation):Foundation.DataProtocol.lastRange<A, B where A1: Foundation.DataProtocol, B1: Swift.RangeExpression, A.Index == B1.Bound>(of: A1, in: B1) -> Swift.Optional<Swift.Range<A.Index>> + 1279
    frame #&#8203;3: 0x00000001220a3662 $__lldb_expr38`main at Untitled Page 2.xcplaygroundpage:12:12
    frame #&#8203;4: 0x0000000104f9b620 MyPlayground3`linkResources + 304
    frame #&#8203;5: 0x0000000106e50aec CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    frame #&#8203;6: 0x0000000106e502b0 CoreFoundation`__CFRunLoopDoBlocks + 336
    frame #&#8203;7: 0x0000000106e4ab34 CoreFoundation`__CFRunLoopRun + 1252
    frame #&#8203;8: 0x0000000106e4a302 CoreFoundation`CFRunLoopRunSpecific + 626
    frame #&#8203;9: 0x000000010ecfe2fe GraphicsServices`GSEventRunModal + 65
    frame #&#8203;10: 0x000000010b017ba2 UIKitCore`UIApplicationMain + 140
    frame #&#8203;11: 0x0000000104f9b6ed MyPlayground3`main + 205
    frame #&#8203;12: 0x00000001087bd541 libdyld.dylib`start + 1
    frame #&#8203;13: 0x00000001087bd541 libdyld.dylib`start + 1

and `lastRange(of: )` returns `firstRange(of:in: )` on master branch currently.
https://github.com/apple/swift-corelibs-foundation/blob/8043670b9d991d45ca72cfadc3806c68e9e16a05/Foundation/DataProtocol.swift#L82-L84

@YOCKOW
Copy link
Member

YOCKOW commented Sep 1, 2019

Opened PR#2499: #2499

@YOCKOW
Copy link
Member

YOCKOW commented Dec 29, 2019

PR for SDK Overlay: swiftlang/swift#28639

@CodaFi
Copy link
Contributor

CodaFi commented Apr 15, 2020

@swift-ci create

@CodaFi
Copy link
Contributor

CodaFi commented Jun 9, 2021

Re-upping the radar here since the original only tracked getting this fixed on Darwin.

@mickeyl
Copy link

mickeyl commented Jun 18, 2021

Is this fixed in the meantime? I have just opened https://bugs.swift.org/browse/SR-14792, which is a duplicate of this very bug.

Needless to say that I'm somewhat shocked that such a basic functionality is still broken on Linux… so much for attempting to cover more than Apple's platforms.

@YOCKOW
Copy link
Member

YOCKOW commented Jun 19, 2021

@mickeyl

#2499 was merged into main 5 days ago. So this issue is fixed. I'm closing this.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from swiftlang/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants