1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

math.big: fix internal subtract_align_last_byte_in_place overflow (#18413)

This commit is contained in:
phoebe
2023-06-12 12:33:53 +02:00
committed by GitHub
parent f73e99cddd
commit 37386697a3
2 changed files with 42 additions and 23 deletions

View File

@ -1,5 +1,6 @@
module big
import math
import math.bits
// suppose operand_a bigger than operand_b and both not null.
@ -96,7 +97,8 @@ fn subtract_align_last_byte_in_place(mut a []u32, b []u32) {
mut new_carry := u32(0)
offset := a.len - b.len
for index := a.len - b.len; index < a.len; index++ {
if a[index] < (b[index - offset] + carry) {
if a[index] < (b[index - offset] + carry)
|| (b[index - offset] == math.max_u32 && carry > 0) {
new_carry = 1
} else {
new_carry = 0