ref: af18284d6b34e27a1dfd11a0340735f13377bbae
parent: bb57346c3c3300542eeb425589d73e121e9d9839
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Nov 23 12:18:51 EST 2025
libdraw: fix icossin2() integer overflow (thanks sleepydog)
--- a/sys/src/libdraw/icossin2.c
+++ b/sys/src/libdraw/icossin2.c
@@ -227,6 +227,7 @@
{int sinsign, cossign, tan, tan10, rem;
short *stp, *ctp;
+ uint ux, uy;
if(x == 0){if(y >= 0)
@@ -238,19 +239,23 @@
sinsign = cossign = 1;
if(x < 0){cossign = -1;
- x = -x;
+ ux = -x;
+ } else {+ ux = x;
}
if(y < 0){sinsign = -1;
- y = -y;
+ uy = -y;
+ } else {+ uy = y;
}
- if(y > x){- tan = 1000*x/y;
+ if(uy > ux){+ tan = 1000*(uvlong)ux/uy;
tan10 = tan/10;
stp = &cosinus[tan10];
ctp = &sinus[tan10];
}else{- tan = 1000*y/x;
+ tan = 1000*(uvlong)uy/ux;
tan10 = tan/10;
stp = &sinus[tan10];
ctp = &cosinus[tan10];
--
⑨