From 6cd099e71b0901bf6f3013f9b56264ebc8b3faf2 Mon Sep 17 00:00:00 2001 From: axxel Date: Sat, 30 Mar 2024 12:32:19 +0100 Subject: [PATCH] BitHacks: remove assert(), fixes #756 This is basically a regression introduced into the MSVC code path in https://github.com/zxing-cpp/zxing-cpp/commit/c661a3f22ee038394c1f9debff0a2d329be4ea05 but the problem was already present in a non-gcc-non-msvc code path. --- core/src/BitHacks.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/BitHacks.h b/core/src/BitHacks.h index c8979289c0..679f91d2b1 100644 --- a/core/src/BitHacks.h +++ b/core/src/BitHacks.h @@ -82,14 +82,13 @@ inline int NumberOfLeadingZeros(T x) template>> inline int NumberOfTrailingZeros(T v) { - assert(v != 0); #ifdef __cpp_lib_bitops return std::countr_zero(static_cast>(v)); #else if constexpr (sizeof(v) <= 4) { static_assert(sizeof(v) == 4, "NumberOfTrailingZeros not implemented for 8 and 16 bit ints."); #ifdef ZX_HAS_GCC_BUILTINS - return __builtin_ctz(v); + return v == 0 ? 32 : __builtin_ctz(v); #elif defined(ZX_HAS_MSC_BUILTINS) unsigned long where; if (_BitScanForward(&where, v)) @@ -108,7 +107,7 @@ inline int NumberOfTrailingZeros(T v) #endif } else { #ifdef ZX_HAS_GCC_BUILTINS - return __builtin_ctzll(v); + return v == 0 ? 64 : __builtin_ctzll(v); #else // including ZX_HAS_MSC_BUILTINS int n = NumberOfTrailingZeros(static_cast(v)); if (n == 32)