Skip to content

Commit

Permalink
Guard nil address (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahsmartin authored Sep 6, 2023
1 parent 6cf6355 commit c8b8f59
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
77 changes: 77 additions & 0 deletions DemoApp/DemoApp.xcodeproj/xcshareddata/xcschemes/DemoApp.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FA1671BE2A5367A800A42DB0"
BuildableName = "DemoApp.app"
BlueprintName = "DemoApp"
ReferencedContainer = "container:DemoApp.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FA1671BE2A5367A800A42DB0"
BuildableName = "DemoApp.app"
BlueprintName = "DemoApp"
ReferencedContainer = "container:DemoApp.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FA1671BE2A5367A800A42DB0"
BuildableName = "DemoApp.app"
BlueprintName = "DemoApp"
ReferencedContainer = "container:DemoApp.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Debug"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
5 changes: 5 additions & 0 deletions Sources/SnapshotPreviewsCore/ConformanceLookup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ private func parseConformance(conformance: UnsafePointer<ProtocolConformanceDesc
let descriptorOffset = Int(conformance.pointee.protocolDescriptor & ~1)
let jumpPtr = UnsafeRawPointer(conformance).advanced(by: MemoryLayout<ProtocolConformanceDescriptor>.offset(of: \.protocolDescriptor)!).advanced(by: descriptorOffset)
let address = jumpPtr.load(as: UInt64.self)

// Address will be 0 if the protocol is not available (such as only defined on a newer OS)
guard address != 0 else {
return nil
}
let protoPtr = UnsafeRawPointer(bitPattern: UInt(address))!
let proto = protoPtr.load(as: ProtocolDescriptor.self)
let namePtr = protoPtr.advanced(by: MemoryLayout<ProtocolDescriptor>.offset(of: \.name)!).advanced(by: Int(proto.name))
Expand Down
4 changes: 2 additions & 2 deletions Sources/SnapshotPreviewsCore/PrecisionModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import Foundation
import SwiftUI

public struct EmergePrecisionModifier: ViewModifier {
let precision: Float
let precision: Float?

public func body(content: Content) -> some View {
content
}
}

extension View {
public func emergeSnapshotPrecision(_ precision: Float) -> some View {
public func emergeSnapshotPrecision(_ precision: Float?) -> some View {
modifier(EmergePrecisionModifier(precision: precision))
}
}

0 comments on commit c8b8f59

Please sign in to comment.