Skip to content

Commit 7b22765

Browse files
committed
Avoid signed integer overflow
1 parent e89650e commit 7b22765

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

jsrc/va1.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ AHDR1(absI2I,D,D){ // linkage requires D
219219
R 0xaaaaaaaa&_mm256_movemask_epi8(_mm256_castpd_si256(anyneg))?EVOFLO:EVOK; //any oflo
220220
)
221221
}
222-
#define XABSI2(u) ({ I2 us=(u)>>(BB*sizeof(I2)-1); u^=us; if(unlikely((u-=us)<0))R EVOFLO; u; })
223-
#define XABSI4(u) ({ I4 us=(u)>>(BB*sizeof(I4)-1); u^=us; if(unlikely((u-=us)<0))R EVOFLO; u; })
224-
// #define XABSI2(u) ({ I2 us=(u)>>(BB*sizeof(I2)-1); u^=us; if(unlikely((u=(I2)((US)u-(US)us))<0))R EVOFLO; u; })
225-
// #define XABSI4(u) ({ I4 us=(u)>>(BB*sizeof(I4)-1); u^=us; if(unlikely((u=(I4)((UI4)u-(UI4)us))<0))R EVOFLO; u; })
222+
// #define XABSI2(u) ({ I2 us=(u)>>(BB*sizeof(I2)-1); u^=us; if(unlikely((u-=us)<0))R EVOFLO; u; })
223+
// #define XABSI4(u) ({ I4 us=(u)>>(BB*sizeof(I4)-1); u^=us; if(unlikely((u-=us)<0))R EVOFLO; u; })
224+
#define XABSI2(u) ({ I2 us=(u)>>(BB*sizeof(I2)-1); u^=us; if(unlikely((u=(I2)((US)u-(US)us))<0))R EVOFLO; u; }) // avoid signed integer overflow
225+
#define XABSI4(u) ({ I4 us=(u)>>(BB*sizeof(I4)-1); u^=us; if(unlikely((u=(I4)((UI4)u-(UI4)us))<0))R EVOFLO; u; })
226226
static APF256C(3,abs,I2,I2,XABSI2)
227227
static APF256C(3,abs,I4,I4,XABSI4)
228228

test/g430.ijs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ a =: i. 1000 1000
583583

584584
6 _. _. _. 15 (= +. *.&(128!:5))"0 (3) +/\ 1 2 3 _. 4 5 6
585585
2 _. _. _. 5 (= +. *.&(128!:5))"0 (3) (+/%#)\ 1 2 3 _. 4 5 6
586+
_. 16 14 12 _. (= +. *.&(128!:5))"0 (3) +/\. 1 2 3 _. 4 5 6
586587

587588

588589
randfini''

0 commit comments

Comments
 (0)