Browse Source

Merge pull request #1358 from Kelimion/big_math_fix

[math/big] Return 0, .Integer_Underflow if T = unsigned and bigint is negative.
Jeroen van Rijn 3 years ago
parent
commit
c771ea9794
1 changed files with 5 additions and 0 deletions
  1. 5 0
      core/math/big/internal.odin

+ 5 - 0
core/math/big/internal.odin

@@ -2362,7 +2362,12 @@ internal_int_get :: proc(a: ^Int, $T: typeid) -> (res: T, err: Error) where intr
 		if a.sign == .Zero_or_Positive {
 			target_bit_size -= 1
 		}
+	} else {
+		if a.sign == .Negative {
+			return 0, .Integer_Underflow
+		}
 	}
+
 	bits_used := internal_count_bits(a)
 
 	if bits_used > target_bit_size {