Suppress the unsigned-integer-overflow sanitizer warnings and do not recover from the integer sanitizer errors (fixes #45) (#73)

This commit is contained in:
Antony Polukhin 2024-02-15 09:24:44 +03:00 committed by GitHub
parent 518e28ff79
commit 3433c34b43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 24 additions and 7 deletions

View File

@ -31,7 +31,7 @@ jobs:
compiler: clang++-10
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
cxxflags: "cxxflags=-fsanitize=address,undefined,integer -fno-sanitize-recover=undefined"
cxxflags: "cxxflags=-fsanitize=address,undefined,integer -fno-sanitize-recover=undefined,integer"
linkflags: "linkflags=-fsanitize=address,undefined,integer"
- toolset: clang
compiler: clang++-14

View File

@ -490,6 +490,9 @@ namespace boost { namespace detail { namespace lcast {
private:
template <typename Type>
#if defined(__clang__) && (__clang_major__ > 3 || __clang_minor__ > 6)
__attribute__((no_sanitize("unsigned-integer-overflow")))
#endif
bool shr_unsigned(Type& output) {
if (start == finish) return false;
CharT const minus = lcast_char_constants<CharT>::minus;
@ -511,6 +514,9 @@ namespace boost { namespace detail { namespace lcast {
}
template <typename Type>
#if defined(__clang__) && (__clang_major__ > 3 || __clang_minor__ > 6)
__attribute__((no_sanitize("unsigned-integer-overflow")))
#endif
bool shr_signed(Type& output) {
if (start == finish) return false;
CharT const minus = lcast_char_constants<CharT>::minus;

View File

@ -120,6 +120,9 @@ struct lexical_cast_dynamic_num_not_ignoring_minus
struct lexical_cast_dynamic_num_ignoring_minus
{
template <typename Target, typename Source>
#if defined(__clang__) && (__clang_major__ > 3 || __clang_minor__ > 6)
__attribute__((no_sanitize("unsigned-integer-overflow")))
#endif
static inline bool try_convert(Source arg, Target& result) noexcept {
typedef typename boost::conditional<
boost::is_float<Source>::value,
@ -129,8 +132,10 @@ struct lexical_cast_dynamic_num_ignoring_minus
typedef typename usource_lazy_t::type usource_t;
if (arg < 0) {
const bool res = boost::detail::noexcept_numeric_convert<Target, usource_t>(0u - arg, result);
result = static_cast<Target>(0u) - static_cast<Target>(result);
const bool res = boost::detail::noexcept_numeric_convert<Target, usource_t>(
static_cast<usource_t>(0u - static_cast<usource_t>(arg)), result
);
result = static_cast<Target>(0u - result);
return res;
} else {
return boost::detail::noexcept_numeric_convert<Target, usource_t>(arg, result);

View File

@ -56,6 +56,9 @@ namespace boost
namespace detail // lcast_to_unsigned
{
template<class T>
#if defined(__clang__) && (__clang_major__ > 3 || __clang_minor__ > 6)
__attribute__((no_sanitize("unsigned-integer-overflow")))
#endif
inline
typename boost::make_unsigned<T>::type lcast_to_unsigned(const T value) noexcept {
typedef typename boost::make_unsigned<T>::type result_type;
@ -251,6 +254,9 @@ namespace boost
private:
// Iteration that does not care about grouping/separators and assumes that all
// input characters are digits
#if defined(__clang__) && (__clang_major__ > 3 || __clang_minor__ > 6)
__attribute__((no_sanitize("unsigned-integer-overflow")))
#endif
inline bool main_convert_iteration() noexcept {
CharT const czero = lcast_char_constants<CharT>::zero;
T const maxv = (std::numeric_limits<T>::max)();

View File

@ -171,9 +171,9 @@ void test_conversion_from_integral_to_string(CharT)
T const max_val = (limits::max)();
T const half_max_val = max_val / 2;
T const cnt = lcast_integral_test_counter; // to suppress warnings
unsigned int const counter = cnt < half_max_val ? cnt : half_max_val;
T const counter = cnt < half_max_val ? cnt : half_max_val;
unsigned int i;
T i = 0;
// Test values around min:
t = min_val;
@ -267,10 +267,10 @@ void test_conversion_from_string_to_integral(CharT)
{
T const half_max_val = max_val / 2;
T const cnt = lcast_integral_test_counter; // to suppress warnings
unsigned int const counter = cnt < half_max_val ? cnt : half_max_val;
T const counter = cnt < half_max_val ? cnt : half_max_val;
T t;
unsigned int i;
T i;
// Test values around min:
t = min_val;