mirror of
https://github.com/opencv/opencv.git
synced 2024-12-14 08:59:11 +08:00
Fix sanitizer issue in countNonZero32f
In that function, the floats are cast to int to be compared to 0. But a float can be -0 or +0, hence define CHECK_NZ_FP(x) ((x)*2 != 0) to remove the sign bit. Except that can trigger the sanitizer: runtime error: signed integer overflow: -1082130432 * 2 cannot be represented in type 'int' Doing everything in uint instead of int is properly defined by the standard.
This commit is contained in:
parent
9dbfba0fd8
commit
16ea1382f7
@ -114,7 +114,7 @@ static int funcname( const T* src, int len ) \
|
|||||||
DEFINE_NONZERO_FUNC(countNonZero8u, u8, u32, uchar, v_uint8, v_uint32, v_eq, v_add_wrap, UPDATE_SUM_U8, CHECK_NZ_INT)
|
DEFINE_NONZERO_FUNC(countNonZero8u, u8, u32, uchar, v_uint8, v_uint32, v_eq, v_add_wrap, UPDATE_SUM_U8, CHECK_NZ_INT)
|
||||||
DEFINE_NONZERO_FUNC(countNonZero16u, u16, u32, ushort, v_uint16, v_uint32, v_eq, v_add_wrap, UPDATE_SUM_U16, CHECK_NZ_INT)
|
DEFINE_NONZERO_FUNC(countNonZero16u, u16, u32, ushort, v_uint16, v_uint32, v_eq, v_add_wrap, UPDATE_SUM_U16, CHECK_NZ_INT)
|
||||||
DEFINE_NONZERO_FUNC(countNonZero32s, s32, s32, int, v_int32, v_int32, v_eq, v_add, UPDATE_SUM_S32, CHECK_NZ_INT)
|
DEFINE_NONZERO_FUNC(countNonZero32s, s32, s32, int, v_int32, v_int32, v_eq, v_add, UPDATE_SUM_S32, CHECK_NZ_INT)
|
||||||
DEFINE_NONZERO_FUNC(countNonZero32f, s32, s32, int, v_int32, v_int32, VEC_CMP_EQ_Z_FP, v_add, UPDATE_SUM_S32, CHECK_NZ_FP)
|
DEFINE_NONZERO_FUNC(countNonZero32f, u32, u32, uint, v_uint32, v_uint32, VEC_CMP_EQ_Z_FP, v_add, UPDATE_SUM_S32, CHECK_NZ_FP)
|
||||||
DEFINE_NONZERO_FUNC(countNonZero16f, u16, u32, ushort, v_uint16, v_uint32, VEC_CMP_EQ_Z_FP16, v_add_wrap, UPDATE_SUM_U16, CHECK_NZ_FP)
|
DEFINE_NONZERO_FUNC(countNonZero16f, u16, u32, ushort, v_uint16, v_uint32, VEC_CMP_EQ_Z_FP16, v_add_wrap, UPDATE_SUM_U16, CHECK_NZ_FP)
|
||||||
|
|
||||||
#undef DEFINE_NONZERO_FUNC_NOSIMD
|
#undef DEFINE_NONZERO_FUNC_NOSIMD
|
||||||
|
Loading…
Reference in New Issue
Block a user