Skip to content

Commit 3fcdb51

Browse files
JustinMeansclaude
andcommitted
Fix signed varint overflow on Linux
Use wrapping subtraction (0 &- x) instead of (~x + 1) to avoid arithmetic overflow with Swift's strict integer checking. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f85d112 commit 3fcdb51

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Sources/Transmission/BinarySerializer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public struct CompactDecoder: Sendable {
106106

107107
public mutating func readVarintSigned() throws -> Int64 {
108108
let unsigned = try readVarint()
109-
let signed = Int64(bitPattern: (unsigned >> 1) ^ (~(unsigned & 1) + 1))
109+
let signed = Int64(bitPattern: (unsigned >> 1) ^ (0 &- (unsigned & 1)))
110110
return signed
111111
}
112112

0 commit comments

Comments
 (0)