From 9196695b2aac231089b4d3c20a73823c16674059 Mon Sep 17 00:00:00 2001 From: Christian Engwer <christi@dune-project.org> Date: Mon, 7 Dec 2009 17:14:23 +0000 Subject: [PATCH] fix FS#621 * implement rangecheck for finite stack (disabled when compiling with NDEBUG) * fix lru with _GLIBCXX_DEBUG [[Imported from SVN: r5753]] --- dune/common/finitestack.hh | 15 +++++++++++++++ dune/common/lru.hh | 2 +- dune/common/test/test-stack.cc | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/dune/common/finitestack.hh b/dune/common/finitestack.hh index 4bd1b5d3d..e9a97920b 100644 --- a/dune/common/finitestack.hh +++ b/dune/common/finitestack.hh @@ -45,18 +45,33 @@ namespace Dune { //! Puts a new object onto the stack void push (const T& t) { +#ifndef NDEBUG + if (full()) + DUNE_THROW(Dune::RangeError, + "trying to call push on a full FiniteStack"); +#endif s[f++] = t; } //! Removes and returns the uppermost object from the stack T pop () { +#ifndef NDEBUG + if (empty()) + DUNE_THROW(Dune::RangeError, + "trying to call top on an empty FiniteStack"); +#endif return s[--f]; } //! Returns the uppermost object on the stack T top () const { +#ifndef NDEBUG + if (empty()) + DUNE_THROW(Dune::RangeError, + "trying to call pop on an empty FiniteStack"); +#endif return s[f-1]; } diff --git a/dune/common/lru.hh b/dune/common/lru.hh index 5cc95e5ee..8439596bb 100644 --- a/dune/common/lru.hh +++ b/dune/common/lru.hh @@ -158,7 +158,7 @@ namespace Dune { /* insert item as mru */ iterator it = _data.insert(_data.begin(), x); /* store index */ - _index[key] = it; + _index.insert(std::make_pair(key,it)); return it->second; } diff --git a/dune/common/test/test-stack.cc b/dune/common/test/test-stack.cc index 479f2e7a9..06c81a3fb 100644 --- a/dune/common/test/test-stack.cc +++ b/dune/common/test/test-stack.cc @@ -47,6 +47,7 @@ int main () { stack1.pop(); // exception has to happen + // make sure you compile this test without NDEBUG std::cerr << "Expected exception Dune::RangeError, but nothing caught\n"; return 1; } catch (Dune::RangeError &e) { -- GitLab