fix ubsan notes

This commit is contained in:
dzaima 2023-04-30 19:43:47 +03:00
parent cd40ec8117
commit 0e79e9f868
3 changed files with 8 additions and 8 deletions

View File

@ -273,17 +273,17 @@ B GRADE_CAT(c1)(B t, B x) {
el32:;
i32* xp = tyany_ptr(x);
i32 min=I32_MAX, max=I32_MIN;
i32 sum=0;
u32 sum=0;
for (usz i = 0; i < ia; i++) {
i32 c = xp[i];
sum += c;
sum += (u32)c;
if (c<min) min=c;
if (c>max) max=c;
}
u64 range = max - (i64)min + 1;
if (range/2 < ia) {
// First try to invert it as a permutation
if (range==ia && sum==(i32)((i64)ia*(min+max)/2)) {
if (range==ia && sum==(u32)(i32)((i64)ia*(min+max)/2)) {
for (usz i = 0; i < ia; i++) rp[i]=ia;
for (usz i = 0; i < ia; i++) { i32 v=xp[i]; GRADE_UD(rp[v-min],rp[max-v])=i; }
bool done=1; for (usz i = 0; i < ia; i++) done &= rp[i]!=ia;

View File

@ -295,14 +295,14 @@ B shape_c2(B t, B w, B x) {
else { r = m_i8arrp ( &rp,nia); }
memset(rp, b, nb);
} else {
if(n==(i16)n) { FILL(i16,i16,(u16)n*0x0001000100010001) }
else { FILL(i32,i32,(u32)n*0x0000000100000001) }
if(n==(i16)n) { FILL(i16,i16,(u16)n*0x0001000100010001U) }
else { FILL(i32,i32,(u32)n*0x0000000100000001U) }
}
} else if (isC32(x)) {
u32 c = o2cG(x);
if (c==(u8 )c) { u8* rp; r = m_c8arrp(&rp,nia); memset(rp, c, nia); }
else if (c==(u16)c) { FILL(c16,u16,c*0x0001000100010001) }
else { FILL(c32,u32,c*0x0000000100000001) }
else if (c==(u16)c) { FILL(c16,u16,c*0x0001000100010001U) }
else { FILL(c32,u32,c*0x0000000100000001U) }
} else {
incBy(x, nia); // in addition with the existing reference, this covers the filled amount & asFill
B rf = asFill(x);

View File

@ -21,7 +21,7 @@ static u64 bqn_hash(B x, const u64 secret[4]) { // doesn't consume
h = m_f64(x.f+0).u;
} else if (isVal(x)) {
return bqn_hashObj(x, secret);
} else if ((x.u<<1) == (0x7FF8000000000000<<1)) {
} else if ((x.u<<1) == (0x7FF8000000000000U<<1)) {
h = secret[1];
} else {
h = x.u;