Skip to content

Commit

Permalink
Fix crash when starting Caffeination with no Opts
Browse files Browse the repository at this point in the history
  • Loading branch information
aaplmath committed Jan 4, 2021
1 parent abc89de commit 5c027b9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
4 changes: 3 additions & 1 deletion CaffeineKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
OBJ_1 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1020;
LastUpgradeCheck = 1230;
TargetAttributes = {
"CaffeineKit::CaffeineKit" = {
LastSwiftMigration = 1020;
Expand Down Expand Up @@ -359,6 +359,7 @@
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -458,6 +459,7 @@
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1230"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -39,8 +39,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -61,8 +59,6 @@
ReferencedContainer = "container:CaffeineKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1230"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -27,6 +27,15 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CaffeineKit::CaffeineKitPackageTests::ProductTarget"
BuildableName = "CaffeineKitPackageTests"
BlueprintName = "CaffeineKitPackageTests"
ReferencedContainer = "container:CaffeineKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -39,17 +48,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CaffeineKit::CaffeineKitPackageTests::ProductTarget"
BuildableName = "CaffeineKitPackageTests"
BlueprintName = "CaffeineKitPackageTests"
ReferencedContainer = "container:CaffeineKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -70,8 +68,6 @@
ReferencedContainer = "container:CaffeineKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
10 changes: 6 additions & 4 deletions Sources/CaffeineKit/Caffeination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,12 @@ public class Caffeination {
guard Caffeination.caffeinateExists else {
throw CaffeinationError.caffeinateNotFound
}
let optsSorted = opts.sorted { $0.argumentList[0] > $1.argumentList[0] }
for i in 1..<optsSorted.count {
if optsSorted[i - 1].argumentList[0] == optsSorted[i].argumentList[0] {
throw CaffeinationError.duplicateOpts
if opts.count > 0 {
let optsSorted = opts.sorted { $0.argumentList[0] > $1.argumentList[0] }
for i in 1..<optsSorted.count {
if optsSorted[i - 1].argumentList[0] == optsSorted[i].argumentList[0] {
throw CaffeinationError.duplicateOpts
}
}
}
}
Expand Down

0 comments on commit 5c027b9

Please sign in to comment.