diff --git a/CHANGELOG.md b/CHANGELOG.md index b6ebba0b..97006584 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Version 187: * Add experimental timeout_socket * Fix warning in file tests +* Fix uninitialized comparison in buffers iterator -------------------------------------------------------------------------------- diff --git a/doc/qbk/09_releases.qbk b/doc/qbk/09_releases.qbk index 5c26a735..cd9989cf 100644 --- a/doc/qbk/09_releases.qbk +++ b/doc/qbk/09_releases.qbk @@ -31,6 +31,8 @@ * ([issue 1267]) Fix parsing of out-of-bounds hex values +* ([issue 1263]) Fix uninitialized comparison in buffers iterator + * Workaround for http-server-fast and libstdc++ [*Experimental] diff --git a/include/boost/beast/core/buffers_adapter.hpp b/include/boost/beast/core/buffers_adapter.hpp index 0e0ce8b0..2000ce24 100644 --- a/include/boost/beast/core/buffers_adapter.hpp +++ b/include/boost/beast/core/buffers_adapter.hpp @@ -69,6 +69,8 @@ class buffers_adapter { } + iter_type end_impl() const; + public: /// The type of the underlying mutable buffer sequence using value_type = MutableBufferSequence; diff --git a/include/boost/beast/core/impl/buffers_adapter.ipp b/include/boost/beast/core/impl/buffers_adapter.ipp index fa0872ae..f077c521 100644 --- a/include/boost/beast/core/impl/buffers_adapter.ipp +++ b/include/boost/beast/core/impl/buffers_adapter.ipp @@ -26,7 +26,7 @@ template class buffers_adapter:: const_buffers_type { - buffers_adapter const* ba_; + buffers_adapter const* b_; public: using value_type = boost::asio::const_buffer; @@ -48,8 +48,8 @@ public: private: friend class buffers_adapter; - const_buffers_type(buffers_adapter const& ba) - : ba_(&ba) + const_buffers_type(buffers_adapter const& b) + : b_(&b) { } }; @@ -59,7 +59,7 @@ class buffers_adapter:: const_buffers_type::const_iterator { iter_type it_; - buffers_adapter const* ba_ = nullptr; + buffers_adapter const* b_ = nullptr; public: using value_type = boost::asio::const_buffer; @@ -78,8 +78,20 @@ public: bool operator==(const_iterator const& other) const { - return ba_ == other.ba_ && - it_ == other.it_; + return + (b_ == nullptr) ? + ( + other.b_ == nullptr || + other.it_ == other.b_->end_impl() + ):( + (other.b_ == nullptr) ? + ( + it_ == b_->end_impl() + ): ( + b_ == other.b_ && + it_ == other.it_ + ) + ); } bool @@ -93,9 +105,9 @@ public: { value_type const b = *it_; return value_type{b.data(), - (ba_->out_ == boost::asio::buffer_sequence_end(ba_->bs_) || - it_ != ba_->out_) ? b.size() : ba_->out_pos_} + - (it_ == ba_->begin_ ? ba_->in_pos_ : 0); + (b_->out_ == boost::asio::buffer_sequence_end(b_->bs_) || + it_ != b_->out_) ? b.size() : b_->out_pos_} + + (it_ == b_->begin_ ? b_->in_pos_ : 0); } pointer @@ -134,33 +146,30 @@ public: private: friend class const_buffers_type; - const_iterator(buffers_adapter const& ba, + const_iterator(buffers_adapter const& b, iter_type iter) : it_(iter) - , ba_(&ba) + , b_(&b) { } }; template -inline auto buffers_adapter:: const_buffers_type::begin() const -> const_iterator { - return const_iterator{*ba_, ba_->begin_}; + return const_iterator{*b_, b_->begin_}; } template -inline auto buffers_adapter:: const_buffers_type::end() const -> const_iterator { - return const_iterator{*ba_, ba_->out_ == - ba_->end_ ? ba_->end_ : std::next(ba_->out_)}; + return const_iterator{*b_, b_->end_impl()}; } //------------------------------------------------------------------------------ @@ -169,7 +178,7 @@ template class buffers_adapter:: mutable_buffers_type { - buffers_adapter const* ba_; + buffers_adapter const* b_; public: using value_type = boost::asio::mutable_buffer; @@ -192,8 +201,8 @@ private: friend class buffers_adapter; mutable_buffers_type( - buffers_adapter const& ba) - : ba_(&ba) + buffers_adapter const& b) + : b_(&b) { } }; @@ -203,7 +212,7 @@ class buffers_adapter:: mutable_buffers_type::const_iterator { iter_type it_; - buffers_adapter const* ba_ = nullptr; + buffers_adapter const* b_ = nullptr; public: using value_type = boost::asio::mutable_buffer; @@ -222,8 +231,20 @@ public: bool operator==(const_iterator const& other) const { - return ba_ == other.ba_ && - it_ == other.it_; + return + (b_ == nullptr) ? + ( + other.b_ == nullptr || + other.it_ == other.b_->end_ + ):( + (other.b_ == nullptr) ? + ( + it_ == b_->end_ + ): ( + b_ == other.b_ && + it_ == other.it_ + ) + ); } bool @@ -237,9 +258,9 @@ public: { value_type const b = *it_; return value_type{b.data(), - it_ == std::prev(ba_->end_) ? - ba_->out_end_ : b.size()} + - (it_ == ba_->out_ ? ba_->out_pos_ : 0); + it_ == std::prev(b_->end_) ? + b_->out_end_ : b.size()} + + (it_ == b_->out_ ? b_->out_pos_ : 0); } pointer @@ -278,10 +299,10 @@ public: private: friend class mutable_buffers_type; - const_iterator(buffers_adapter const& ba, + const_iterator(buffers_adapter const& b, iter_type iter) : it_(iter) - , ba_(&ba) + , b_(&b) { } }; @@ -294,7 +315,7 @@ mutable_buffers_type:: begin() const -> const_iterator { - return const_iterator{*ba_, ba_->out_}; + return const_iterator{*b_, b_->out_}; } template @@ -305,11 +326,20 @@ mutable_buffers_type:: end() const -> const_iterator { - return const_iterator{*ba_, ba_->end_}; + return const_iterator{*b_, b_->end_}; } //------------------------------------------------------------------------------ +template +auto +buffers_adapter:: +end_impl() const -> + iter_type +{ + return out_ == end_ ? end_ : std::next(out_); +} + template buffers_adapter:: buffers_adapter(buffers_adapter&& other) diff --git a/include/boost/beast/core/impl/buffers_cat.ipp b/include/boost/beast/core/impl/buffers_cat.ipp index 2e82e887..81fe8c16 100644 --- a/include/boost/beast/core/impl/buffers_cat.ipp +++ b/include/boost/beast/core/impl/buffers_cat.ipp @@ -281,9 +281,20 @@ buffers_cat_view:: const_iterator:: operator==(const_iterator const& other) const { - if(bn_ != other.bn_) - return false; - return it_ == other.it_; + return + (bn_ == nullptr) ? + ( + other.bn_ == nullptr || + other.it_.index() == sizeof...(Bn) + ):( + (other.bn_ == nullptr) ? + ( + it_.index() == sizeof...(Bn) + ): ( + bn_ == other.bn_ && + it_ == other.it_ + ) + ); } template diff --git a/include/boost/beast/core/impl/buffers_prefix.ipp b/include/boost/beast/core/impl/buffers_prefix.ipp index 783cf19c..c595455d 100644 --- a/include/boost/beast/core/impl/buffers_prefix.ipp +++ b/include/boost/beast/core/impl/buffers_prefix.ipp @@ -73,7 +73,20 @@ public: bool operator==(const_iterator const& other) const { - return b_ == other.b_ && it_ == other.it_; + return + (b_ == nullptr) ? + ( + other.b_ == nullptr || + other.it_ == other.b_->end_ + ):( + (other.b_ == nullptr) ? + ( + it_ == b_->end_ + ): ( + b_ == other.b_ && + it_ == other.it_ + ) + ); } bool @@ -139,6 +152,8 @@ private: } }; +//------------------------------------------------------------------------------ + template void buffers_prefix_view:: diff --git a/include/boost/beast/core/impl/buffers_suffix.ipp b/include/boost/beast/core/impl/buffers_suffix.ipp index 4385fe50..62b5f463 100644 --- a/include/boost/beast/core/impl/buffers_suffix.ipp +++ b/include/boost/beast/core/impl/buffers_suffix.ipp @@ -54,7 +54,20 @@ public: bool operator==(const_iterator const& other) const { - return b_ == other.b_ && it_ == other.it_; + return + (b_ == nullptr) ? + ( + other.b_ == nullptr || + other.it_ == boost::asio::buffer_sequence_end(other.b_->bs_) + ):( + (other.b_ == nullptr) ? + ( + it_ == boost::asio::buffer_sequence_end(b_->bs_) + ): ( + b_ == other.b_ && + it_ == other.it_ + ) + ); } bool