Skip to content

Commit fc05e46

Browse files
authored
Merge pull request #466 from dinesharjani/dfuerror-crash
Fix for force-unwrap crash in DFURemoteError.with(code:)
2 parents f73213f + 817d906 commit fc05e46

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

iOSDFULibrary/Classes/Implementation/DFUServiceDelegate.swift

+7-5
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ internal enum DFURemoteError : Int {
3737
case buttonless = 90
3838
case experimentalButtonless = 9000
3939

40+
/// Returns a representative ``DFUError``
41+
///
42+
/// The only available codes that this method is called with are
43+
/// hardcoded in the library (ButtonlessDFU, DFUControlPoint,
44+
/// SecureDFUControlPoint). But, we have seen crashes so,
45+
/// we are returning ``DFUError.unsupportedResponse`` if a code is not found.
4046
func with(code: UInt8) -> DFUError {
41-
// The force-unwrap here is used, as the only available codes
42-
// that this method is called with are hardcoded in the library
43-
// (ButtonlessDFU, DFUControlPoint, SecureDFUControlPoint)
44-
// and, with the optional offset, will match an existing DFUError.
45-
return DFUError(rawValue: Int(code) + rawValue)!
47+
return DFUError(rawValue: Int(code) + rawValue) ?? .unsupportedResponse
4648
}
4749
}
4850

0 commit comments

Comments
 (0)