Better fix

This commit is contained in:
Alexey Milovidov 2021-04-01 03:44:02 +03:00
parent c9fac714b4
commit 7589a014f9
2 changed files with 12 additions and 10 deletions

View File

@ -25,6 +25,12 @@ namespace common
return x - y;
}
template <typename T>
inline auto NO_SANITIZE_UNDEFINED negateIgnoreOverflow(T x)
{
return -x;
}
template <typename T>
inline bool addOverflow(T x, T y, T & res)
{

View File

@ -6,7 +6,9 @@
#include <DataTypes/DataTypesNumber.h>
#include <Functions/FunctionFactory.h>
#include <Functions/FunctionHelpers.h>
#include "Core/ColumnWithTypeAndName.h"
#include <common/arithmeticOverflow.h>
#include <Core/ColumnWithTypeAndName.h>
namespace DB
{
@ -120,12 +122,6 @@ private:
return res;
}
template <typename T>
static inline auto NO_SANITIZE_UNDEFINED negate(T x)
{
return -x;
}
template <typename KeyType, bool is_str_key, typename ValType>
ColumnPtr execute2(size_t row_count, TupleMaps & args, const DataTypeTuple & res_type) const
{
@ -178,14 +174,14 @@ private:
{
const auto [it, inserted] = summing_map.insert({key, value});
if (!inserted)
it->second += value;
it->second = common::addIgnoreOverflow(it->second, value);
}
else
{
static_assert(op_type == OpTypes::SUBTRACT);
const auto [it, inserted] = summing_map.insert({key, first ? value : negate(value)});
const auto [it, inserted] = summing_map.insert({key, first ? value : common::negateIgnoreOverflow(value)});
if (!inserted)
it->second -= value;
it->second = common::subIgnoreOverflow(it->second, value);
}
}