From 983141b4f9b8dafd9eb1e09838907de91de5e2cd Mon Sep 17 00:00:00 2001 From: Kususumu <39623331+Kususumu@users.noreply.github.com> Date: Wed, 9 Jun 2021 10:14:14 +0800 Subject: [PATCH] Fix a long time ping cause app crash UInt16(65536) cause app crash: ``` SwiftyPing.swift 362: let icmpPackage = try self.createICMPPackage(identifier: UInt16(self.identifier), sequenceNumber: UInt16(self.sequenceIndex)) ``` when the sequenceIndex keep plus up to Int.max > 65535 : ``` private func incrementSequenceIndex() { // Handle overflow gracefully if sequenceIndex >= Int.max { sequenceIndex = 0 } else { sequenceIndex += 1 } } ``` we can fix it to set the max of sequenceIndex to UInt16.max --- Sources/SwiftyPing/SwiftyPing.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftyPing/SwiftyPing.swift b/Sources/SwiftyPing/SwiftyPing.swift index 4894a35..0c6f2d3 100644 --- a/Sources/SwiftyPing/SwiftyPing.swift +++ b/Sources/SwiftyPing/SwiftyPing.swift @@ -532,7 +532,7 @@ public class SwiftyPing: NSObject { private func incrementSequenceIndex() { // Handle overflow gracefully - if sequenceIndex >= Int.max { + if sequenceIndex >= UInt16.max { sequenceIndex = 0 } else { sequenceIndex += 1