Skip to content

Commit a6dc986

Browse files
authored
Change 'unsafeDowncast' to 'as!' (#115)
Motivation: The 'unsafeDowncast' can cause a miscompile leading to unexpected runtime behaviour. Modifications: - Use 'as!' instead Result: No miscompiles on 5.10
1 parent b50f877 commit a6dc986

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Sources/Prometheus/NIOLock.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ final class LockStorage<Value>: ManagedBuffer<Value, LockPrimitive> {
141141
let buffer = Self.create(minimumCapacity: 1) { _ in
142142
return value
143143
}
144-
let storage = unsafeDowncast(buffer, to: Self.self)
144+
// Avoid 'unsafeDowncast' as there is a miscompilation on 5.10.
145+
let storage = buffer as! Self
145146

146147
storage.withUnsafeMutablePointers { _, lockPtr in
147148
LockOperations.create(lockPtr)

0 commit comments

Comments
 (0)