Skip to content

Commit f8c286a

Browse files
authored
Be explicit about the type and bound we're checking in BytecodeReader.nextInt32. (apple#1859)
Thanks to a heterogeneous comparison operator on `BinaryInteger`, the expression `someUInt64 < 1 &<< 32` was compiling incorrectly on 32-bit architectures, because the right-hand side was being inferred as `Int` instead of `UInt64`. And on a 32-bit system, `1 &<< 32` is zero. Fixes apple#1858.
1 parent 05f940e commit f8c286a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Sources/SwiftProtobuf/BytecodeReader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ package struct BytecodeReader<Instruction: RawRepresentable> where Instruction.R
6868
// `Int32`s are stored by converting them bit-wise to a `UInt32` and then zero-extended to
6969
// `UInt64`, since this representation is smaller than sign-extending them to 64 bits.
7070
let uint64Value = nextUInt64()
71-
assert(uint64Value < 1 &<< 32, "nextInt32() read a value larger than 32 bits")
71+
assert(uint64Value < UInt64(0x1_0000_0000), "nextInt32() read a value larger than 32 bits")
7272
return Int32(bitPattern: UInt32(truncatingIfNeeded: uint64Value))
7373
}
7474

0 commit comments

Comments
 (0)