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-4308] Closure + SecRandomCopyBytes doesn't generate random bytes with -O/-OWholeModule #46891

Closed
swift-ci opened this issue Mar 21, 2017 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself optimized only Flag: An issue whose reproduction requires optimized compilation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-4308
Radar None
Original Reporter sleroux (JIRA User)
Type Bug
Status Resolved
Resolution Invalid
Environment

Xcode 8.2

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, OptimizedOnly
Assignee None
Priority Medium

md5: 13c08eefc137d5df2e8e69a322409019

Issue Description:

I apologize in advance as I'm not 100% certain if it's either the SecRandomCopyBytes call or the closures it's wrapped in but it seems that when -O or -OWholeModule is enabled, the random bytes generated by SecRandomCopyBytes results in a bunch of "A" strings when the bytes are converted to a base64 string.

The code I was able to reproduce this issue with is located here: mozilla-mobile/firefox-ios#2544

If needed, I can distill this down into a test project that only uses this method to reproduce this case.

@belkadan
Copy link
Contributor

You put your call to SecRandomCopyBytes inside a call to assert. assert is not invoked in optimized builds. You can use precondition for checks that are still active under normal optimization, but they'd still be optimized out in -Ounchecked builds (were you ever to do that).

In general, you shouldn't put computation inside assertions.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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 optimized only Flag: An issue whose reproduction requires optimized compilation
Projects
None yet
Development

No branches or pull requests

2 participants