Skip to content
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

[SR-6616] Crash when assigning tuple with Array to UnsafeMutablePointer #49165

Closed
zienag opened this issue Dec 14, 2017 · 3 comments
Closed

[SR-6616] Crash when assigning tuple with Array to UnsafeMutablePointer #49165

zienag opened this issue Dec 14, 2017 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution standard library Area: Standard library umbrella

Comments

@zienag
Copy link

zienag commented Dec 14, 2017

Previous ID SR-6616
Radar rdar://problem/36048674
Original Reporter @zienag
Type Bug
Status Resolved
Resolution Invalid
Environment

$ swift --version

Apple Swift version 4.0.2 (swiftlang-900.0.69.2 clang-900.0.38)

Target: x86_64-apple-macosx10.9

Additional Detail from JIRA
Votes 0
Component/s Compiler, Standard Library
Labels Bug, RunTimeCrash
Assignee @zienag
Priority Medium

md5: e84d57b482bbf3e99afff2ba5f034a9d

Issue Description:

$ cat main.swift

let p = UnsafeMutablePointer<(Int, [Int])>.allocate(capacity: 2)

p[0] = (1, [1])

p[1] = (2, [2])

Crash with EXC_BAD_ACCESS:

* thread #&#8203;1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)

{{ * frame #0: 0x00000001004d2423 test`swift_release + 19}}

{{ frame #1: 0x000000010000210a test`main at main.swift:17}}

{{ frame #2: 0x00007fffd13b6235 libdyld.dylib`start + 1}}

It reproduces always when debugger connected, and in about 50% without debugger.

@belkadan
Copy link
Contributor

Reproduced with near-master.

@swift-ci create

@eeckstein
Copy link
Member

After allocation, the memory is uninitialized and has to be initialized with one of the initialize methods.
Otherwise, the assignment will try to release the old array (the second tuple element), which is garbage at that point.

@eeckstein
Copy link
Member

Alfred, can you please try to use "initialize" and see if this resolves the problem?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

4 participants