Skip to content

Commit

Permalink
Change 'unsafeDowncast' to 'as!' (#52)
Browse files Browse the repository at this point in the history
Motivation:

The 'unsafeDowncast' can cause a miscompile leading to unexpected
runtime behaviour.

Modifications:

- Use 'as!' instead

Result:

No miscompiles on 5.10
  • Loading branch information
glbrntt authored Jul 24, 2024
1 parent 50e1f4a commit 9bf4c71
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Sources/OpenAPIURLSession/BufferedStream/Lock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ final class LockStorage<Value>: ManagedBuffer<Value, LockPrimitive> {
let buffer = Self.create(minimumCapacity: 1) { _ in
return value
}
let storage = unsafeDowncast(buffer, to: Self.self)
// Avoid 'unsafeDowncast' as there is a miscompilation on 5.10.
let storage = buffer as! Self

storage.withUnsafeMutablePointers { _, lockPtr in
LockOperations.create(lockPtr)
Expand Down

0 comments on commit 9bf4c71

Please sign in to comment.