diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2021-12-09 16:31:54 +0100 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2021-12-09 16:31:54 +0100 |
| commit | b2b79b86f00a229cc9d9cc0226ffb594a4e4d910 (patch) | |
| tree | b45edc26c3fa36938d3235c6383d014b59e7db2b | |
| parent | c94098c2ab550425075509e3031bacc3a588a6db (diff) | |
[math/big] Return 0, .Integer_Underflow if trying to get a negative number to an unsigned int.
| -rw-r--r-- | core/math/big/internal.odin | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/core/math/big/internal.odin b/core/math/big/internal.odin index abe592f9b..70914228e 100644 --- a/core/math/big/internal.odin +++ b/core/math/big/internal.odin @@ -2332,7 +2332,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 { |