ref: b0d5eb7b57110dbc8c0d40f94f570541e82ac209
parent: d658e39bc35277b5405c1f64e6f373bf62de4ad6
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Jan 29 22:12:06 EST 2025
itomp: fix INT32_MIN case
--- a/3rd/mp/mptoi.c
+++ b/3rd/mp/mptoi.c
@@ -9,12 +9,16 @@
mpint*
itomp(int i, mpint *b)
{
- if(b == nil){
+ if(b == nil)
b = mpnew(0);
+ if(i == INT32_MIN){
+ b->sign = -1;
+ *b->p = (mpdigit)INT32_MAX+1;
+ }else{
+ b->sign = (i >> (sizeof(i)*8 - 1)) | 1;
+ i *= b->sign;
+ *b->p = i;
}
- b->sign = (i >> (sizeof(i)*8 - 1)) | 1;
- i *= b->sign;
- *b->p = i;
b->top = 1;
return mpnorm(b);
}