From 16ea1382f729a5e91b7f78592928a83f174d82c1 Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Thu, 10 Oct 2024 13:35:49 +0200 Subject: [PATCH] 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. --- modules/core/src/count_non_zero.simd.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/count_non_zero.simd.hpp b/modules/core/src/count_non_zero.simd.hpp index eb854d0afd..0acd75544f 100644 --- a/modules/core/src/count_non_zero.simd.hpp +++ b/modules/core/src/count_non_zero.simd.hpp @@ -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(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(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) #undef DEFINE_NONZERO_FUNC_NOSIMD