From 3956bdbb78e3924055651ecab4234d3246215419 Mon Sep 17 00:00:00 2001 From: Dmitry Arkhipov Date: Fri, 2 Jun 2023 16:17:27 +0300 Subject: [PATCH] fix asan failures Changes to array sizes in tests are due to asan bug. --- include/boost/json/basic_parser_impl.hpp | 9 ++++++++- include/boost/json/impl/value_stack.ipp | 6 ++++-- test/monotonic_resource.cpp | 9 +++++++-- test/value_from.cpp | 2 +- test/value_to.cpp | 2 +- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/include/boost/json/basic_parser_impl.hpp b/include/boost/json/basic_parser_impl.hpp index e6368051a..b708f595f 100644 --- a/include/boost/json/basic_parser_impl.hpp +++ b/include/boost/json/basic_parser_impl.hpp @@ -290,6 +290,7 @@ const char* basic_parser:: fail(const char* p) noexcept { + BOOST_ASSERT( p != sentinel() ); end_ = p; return sentinel(); } @@ -302,6 +303,7 @@ fail( error ev, source_location const* loc) noexcept { + BOOST_ASSERT( p != sentinel() ); end_ = p; ec_.assign(ev, loc); return sentinel(); @@ -314,7 +316,8 @@ maybe_suspend( const char* p, state st) { - end_ = p; + if( p != sentinel() ) + end_ = p; if(BOOST_JSON_LIKELY(more_)) { // suspend @@ -332,6 +335,7 @@ maybe_suspend( state st, std::size_t n) { + BOOST_ASSERT( p != sentinel() ); end_ = p; if(BOOST_JSON_LIKELY(more_)) { @@ -351,6 +355,7 @@ maybe_suspend( state st, const number& num) { + BOOST_ASSERT( p != sentinel() ); end_ = p; if(BOOST_JSON_LIKELY(more_)) { @@ -369,6 +374,7 @@ suspend( const char* p, state st) { + BOOST_ASSERT( p != sentinel() ); end_ = p; // suspend reserve(); @@ -384,6 +390,7 @@ suspend( state st, const number& num) { + BOOST_ASSERT( p != sentinel() ); end_ = p; // suspend num_ = num; diff --git a/include/boost/json/impl/value_stack.ipp b/include/boost/json/impl/value_stack.ipp index 33575da05..af1b107b2 100644 --- a/include/boost/json/impl/value_stack.ipp +++ b/include/boost/json/impl/value_stack.ipp @@ -129,6 +129,7 @@ grow_one() reinterpret_cast( sp_->allocate( new_cap * sizeof(value))); + std::size_t const cur_size = top_ - begin_; if(begin_) { std::memcpy( @@ -140,7 +141,7 @@ grow_one() capacity * sizeof(value)); } // book-keeping - top_ = begin + (top_ - begin_); + top_ = begin + cur_size; end_ = begin + new_cap; begin_ = begin; } @@ -170,6 +171,7 @@ grow(std::size_t nchars) reinterpret_cast( sp_->allocate( new_cap * sizeof(value))); + std::size_t const cur_size = top_ - begin_; if(begin_) { std::size_t amount = @@ -185,7 +187,7 @@ grow(std::size_t nchars) capacity * sizeof(value)); } // book-keeping - top_ = begin + (top_ - begin_); + top_ = begin + cur_size; end_ = begin + new_cap; begin_ = begin; } diff --git a/test/monotonic_resource.cpp b/test/monotonic_resource.cpp index f74777541..91eeaf2cc 100644 --- a/test/monotonic_resource.cpp +++ b/test/monotonic_resource.cpp @@ -34,8 +34,13 @@ class monotonic_resource_test std::size_t buffer_size) { using ptr_t = const volatile unsigned char*; - return reinterpret_cast(ptr) >= reinterpret_cast(buffer) && - reinterpret_cast(ptr) < reinterpret_cast(buffer) + buffer_size; + return + std::greater_equal()( + reinterpret_cast(ptr), + reinterpret_cast(buffer)) && + std::less()( + reinterpret_cast(ptr), + reinterpret_cast(buffer) + buffer_size); } bool diff --git a/test/value_from.cpp b/test/value_from.cpp index b7703a286..17e69e994 100644 --- a/test/value_from.cpp +++ b/test/value_from.cpp @@ -354,7 +354,7 @@ class value_from_test BOOST_TEST(serialize(c) == serialize(b)); } { - std::array a; + std::array a; a.fill(0); value b; diff --git a/test/value_to.cpp b/test/value_to.cpp index 86fa4ebac..7a64cc44b 100644 --- a/test/value_to.cpp +++ b/test/value_to.cpp @@ -279,7 +279,7 @@ class value_to_test ctx... ); { - std::array arr; + std::array arr; arr.fill(0); BOOST_TEST_CONV( arr, ctx... ); }