From 9bf4c712ad7989d6a91dbe68748b8829a50837e4 Mon Sep 17 00:00:00 2001 From: George Barnett Date: Wed, 24 Jul 2024 20:31:27 +0100 Subject: [PATCH] Change 'unsafeDowncast' to 'as!' (#52) Motivation: The 'unsafeDowncast' can cause a miscompile leading to unexpected runtime behaviour. Modifications: - Use 'as!' instead Result: No miscompiles on 5.10 --- Sources/OpenAPIURLSession/BufferedStream/Lock.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/OpenAPIURLSession/BufferedStream/Lock.swift b/Sources/OpenAPIURLSession/BufferedStream/Lock.swift index db78c8b..b6e82e2 100644 --- a/Sources/OpenAPIURLSession/BufferedStream/Lock.swift +++ b/Sources/OpenAPIURLSession/BufferedStream/Lock.swift @@ -111,7 +111,8 @@ final class LockStorage: ManagedBuffer { 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)