| ... | @@ -451,7 +451,7 @@ pub fn safeAdd(a: anytype, b: anytype) @TypeOf(a) { | ... | @@ -451,7 +451,7 @@ pub fn safeAdd(a: anytype, b: anytype) @TypeOf(a) { |
| 451 | if (b >= 0) { | 451 | if (b >= 0) { |
| 452 | return a + @as(@TypeOf(a), @intCast(b)); | 452 | return a + @as(@TypeOf(a), @intCast(b)); |
| 453 | } | 453 | } |
| 454 | return a - @as(@TypeOf(a), @intCast(-b)); | 454 | return a - @as(@TypeOf(a), @intCast(-@as(OneBiggerInt(@TypeOf(b)), b))); |
| 455 | } | 455 | } |
| 456 | | 456 | |
| 457 | pub fn readBytesAlloc(reader: anytype, alloc: std.mem.Allocator, len: usize) ![]u8 { | 457 | pub fn readBytesAlloc(reader: anytype, alloc: std.mem.Allocator, len: usize) ![]u8 { |
| ... | @@ -651,3 +651,9 @@ pub fn joinPartial(comptime P: type, a: P, b: P) P { | ... | @@ -651,3 +651,9 @@ pub fn joinPartial(comptime P: type, a: P, b: P) P { |
| 651 | } | 651 | } |
| 652 | return temp; | 652 | return temp; |
| 653 | } | 653 | } |
| | 654 | |
| | 655 | pub fn OneBiggerInt(comptime T: type) type { |
| | 656 | var info = @typeInfo(T); |
| | 657 | info.Int.bits += 1; |
| | 658 | return @Type(info); |
| | 659 | } |