ref: 2140c98e1eaf198b4afb8a22dc68a3a011832ffb
parent: b0d5eb7b57110dbc8c0d40f94f570541e82ac209
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Jan 30 21:58:04 EST 2025
vtomp: fix another UB
--- a/3rd/mp/mptov.c
+++ b/3rd/mp/mptov.c
@@ -13,12 +13,17 @@
int s;
uint64_t uv;
- if(b == nil){
+ if(b == nil)
b = mpnew(VLDIGITS*Dbits);
- }else
+ else
mpbits(b, VLDIGITS*Dbits);
- b->sign = (v >> (sizeof(v)*8 - 1)) | 1;
- uv = v * b->sign;
+ if(v == INT64_MIN){
+ b->sign = -1;
+ uv = (mpdigit)INT64_MAX+1;
+ }else{
+ b->sign = (v >> (sizeof(v)*8 - 1)) | 1;
+ uv = v * b->sign;
+ }
for(s = 0; s < VLDIGITS; s++){
b->p[s] = uv;
#ifndef BITS64