mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-03 04:52:10 +00:00
7da4083237
This will fix the following UB report [1]: "../src/Functions/bitAnd.cpp:24:61: runtime error: nan is outside the range of representable values of type 'long' Received signal -3 Received signal Unknown signal (-3)" [1]: https://clickhouse-test-reports.s3.yandex.net/19824/89c4055202b9d08459f90ee5791d4e3017b82fbf/fuzzer_ubsan/report.html#fail1
47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
#include <Functions/FunctionFactory.h>
|
|
#include <Functions/FunctionBinaryArithmetic.h>
|
|
#include <Core/Defines.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
namespace ErrorCodes
|
|
{
|
|
extern const int NOT_IMPLEMENTED;
|
|
}
|
|
|
|
namespace
|
|
{
|
|
|
|
template <typename A, typename B>
|
|
struct BitTestImpl
|
|
{
|
|
using ResultType = UInt8;
|
|
static const constexpr bool allow_fixed_string = false;
|
|
|
|
template <typename Result = ResultType>
|
|
NO_SANITIZE_UNDEFINED static inline Result apply(A a [[maybe_unused]], B b [[maybe_unused]])
|
|
{
|
|
if constexpr (is_big_int_v<A> || is_big_int_v<B>)
|
|
throw Exception("bitTest is not implemented for big integers as second argument", ErrorCodes::NOT_IMPLEMENTED);
|
|
else
|
|
return (typename NumberTraits::ToInteger<A>::Type(a) >> typename NumberTraits::ToInteger<B>::Type(b)) & 1;
|
|
}
|
|
|
|
#if USE_EMBEDDED_COMPILER
|
|
static constexpr bool compilable = false; /// TODO
|
|
#endif
|
|
};
|
|
|
|
struct NameBitTest { static constexpr auto name = "bitTest"; };
|
|
using FunctionBitTest = BinaryArithmeticOverloadResolver<BitTestImpl, NameBitTest, true, false>;
|
|
|
|
}
|
|
|
|
void registerFunctionBitTest(FunctionFactory & factory)
|
|
{
|
|
factory.registerFunction<FunctionBitTest>();
|
|
}
|
|
|
|
}
|