diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index 2db21429cd..84a5cd41c9 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -3632,6 +3632,7 @@ fn llmulaccKaratsuba( /// r = r (op) a. /// The result is computed modulo `r.len`. fn llaccum(comptime op: AccOp, r: []Limb, a: []const Limb) void { + assert(!slicesOverlap(r, a) or @intFromPtr(r.ptr) <= @intFromPtr(a.ptr)); if (op == .sub) { _ = llsubcarry(r, r, a); return; @@ -3701,6 +3702,8 @@ fn llmulaccLong(comptime op: AccOp, r: []Limb, a: []const Limb, b: []const Limb) /// The result is computed modulo `r.len`. /// Returns whether the operation overflowed. fn llmulLimb(comptime op: AccOp, acc: []Limb, y: []const Limb, xi: Limb) bool { + assert(!slicesOverlap(acc, y) or @intFromPtr(acc.ptr) <= @intFromPtr(y.ptr)); + if (xi == 0) { return false; } @@ -3763,6 +3766,8 @@ fn llsubcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb { assert(a.len != 0 and b.len != 0); assert(a.len >= b.len); assert(r.len >= a.len); + assert(!slicesOverlap(r, a) or @intFromPtr(r.ptr) <= @intFromPtr(a.ptr)); + assert(!slicesOverlap(r, b) or @intFromPtr(r.ptr) <= @intFromPtr(b.ptr)); var i: usize = 0; var borrow: Limb = 0; @@ -3794,6 +3799,8 @@ fn lladdcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb { assert(a.len != 0 and b.len != 0); assert(a.len >= b.len); assert(r.len >= a.len); + assert(!slicesOverlap(r, a) or @intFromPtr(r.ptr) <= @intFromPtr(a.ptr)); + assert(!slicesOverlap(r, b) or @intFromPtr(r.ptr) <= @intFromPtr(b.ptr)); var i: usize = 0; var carry: Limb = 0;