Skip to content

Commit 50f3241

Browse files
authored
[stdlib] _Int128: fix invalid overflow crash #65703
2 parents 595aefd + ecf9775 commit 50f3241

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

stdlib/public/core/Int128.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ extension _${U}Int128: FixedWidthInteger {
257257
by rhs: Self
258258
) -> (partialValue: Self, overflow: Bool) {
259259
% if signed:
260-
let isNegative = (self._isNegative != rhs._isNegative)
260+
let isNegative = (self._isNegative != rhs._isNegative && self != .zero && rhs != .zero)
261261
let (p, overflow) = self.magnitude.multipliedReportingOverflow(
262262
by: rhs.magnitude)
263263
let r = _Int128(bitPattern: isNegative ? p._twosComplement : p)
@@ -281,7 +281,7 @@ extension _${U}Int128: FixedWidthInteger {
281281
by other: UInt64
282282
) -> (partialValue: Self, overflow: Bool) {
283283
% if signed:
284-
let isNegative = self._isNegative
284+
let isNegative = self._isNegative && self != .zero && other != .zero
285285
let (p, overflow) = self.magnitude.multipliedReportingOverflow(by: other)
286286
let r = _Int128(bitPattern: isNegative ? p._twosComplement : p)
287287
return (r, overflow || (isNegative != r._isNegative))

0 commit comments

Comments
 (0)