From cfba000ffac670b0bf92c11941d529a895631254 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Fri, 31 Mar 2017 02:15:55 +1100 Subject: [PATCH] Updated to Boost Version 1.63.0 Fixed bug where `operator[]` was used to read the address of the one-past-the-end element of a `boost::container::vector`. --- ext/ExternalDependencies.txt | 2 +- src/LayeredCanvas.cpp | 5 +---- src/multi_vector.h | 11 ++++++++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ext/ExternalDependencies.txt b/ext/ExternalDependencies.txt index c01fda3f..c1561d34 100644 --- a/ext/ExternalDependencies.txt +++ b/ext/ExternalDependencies.txt @@ -1,7 +1,7 @@ ==== HourglassII External Dependencies Configuration ==== HourglassII depends on the following libraries: -Boost version 1.59.0 -- http://www.boost.org/users/history/version_1_59_0.html +Boost version 1.63.0 -- http://www.boost.org/users/history/version_1_63_0.html SFML version 2.4.2 -- http://www.sfml-dev.org/download.php Threading Building Blocks version 2017 Update 5 -- http://threadingbuildingblocks.org diff --git a/src/LayeredCanvas.cpp b/src/LayeredCanvas.cpp index 557500f8..7329fc8a 100644 --- a/src/LayeredCanvas.cpp +++ b/src/LayeredCanvas.cpp @@ -4,9 +4,6 @@ #include #include -#include -#include - namespace hg { namespace lc_internal { @@ -129,7 +126,7 @@ Flusher LayeredCanvas::getFlusher() { void Flusher::partialFlush(int upperLimit) { boost::container::vector::iterator lowerBound(upperBound); upperBound = std::upper_bound(lowerBound, boost::end(canvas->drawCalls), DrawCall{upperLimit, clone_ptr(nullptr)}); - std::for_each(lowerBound, upperBound, boost::bind(&DrawCall::drawTo, _1, boost::ref(*canvas->canvas))); + std::for_each(lowerBound, upperBound, [this](lc_internal::DrawCall const &drawCall) { drawCall.drawTo(*canvas->canvas); }); } Flusher::Flusher(LayeredCanvas *canvas) : canvas(canvas) { boost::stable_sort(canvas->drawCalls); diff --git a/src/multi_vector.h b/src/multi_vector.h index fcc86edd..4c8af263 100644 --- a/src/multi_vector.h +++ b/src/multi_vector.h @@ -177,9 +177,18 @@ class multi_vector { static std::size_t const current_axis = N_dims - 1; //public: U &operator[](std::size_t i) const { + //These two assertions could be placed in a constructor. + //They do not depend on i. + assert(this_->data.size() >= this_->size[current_axis]); + assert(std::less_equal<>()(array_start, this_->data.data() + this_->data.size())); + assert(std::less_equal<>()(array_start, this_->data.data() + this_->data.size() - this_->size[current_axis])); + assert(current_axis < this_->size.size()); assert(i < this_->size[current_axis]); - assert(array_start+i >= this_->data.data() && array_start+i < &this_->data[this_->data.size()]); + //TODO: This assert invokes undefined behaviour if violated! (Due to inter-array comparisons/creation of invalid pointers) + //Not sure how to avoid this. I believe the earlier assertions in combination are equivalent to this assertion; so maybe this + //assertion can just be removed. + assert(array_start+i >= this_->data.data() && array_start+i < this_->data.data() + this_->data.size()); return array_start[i]; } };