From: Timo Heister Date: Wed, 22 Jul 2015 19:42:31 +0000 (-0400) Subject: fix invalid operation in DynamicSparsityPattern::iterator X-Git-Tag: v8.3.0-rc2~4^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10397b89d1de15f7bfd378ad573eec66d693505d;p=dealii.git fix invalid operation in DynamicSparsityPattern::iterator We used to compare two std::vector iterators that might belong to different std::vectors. This is obviously illegal. This addresses issue #1175, see https://github.com/dealii/dealii/issues/1175 Add a test that failed (with stl debug library only). Conflicts: doc/news/changes.h --- diff --git a/include/deal.II/lac/dynamic_sparsity_pattern.h b/include/deal.II/lac/dynamic_sparsity_pattern.h index d7e4629ca5..458c4cba1f 100644 --- a/include/deal.II/lac/dynamic_sparsity_pattern.h +++ b/include/deal.II/lac/dynamic_sparsity_pattern.h @@ -739,9 +739,8 @@ namespace DynamicSparsityPatternIterators // current_entry field may not point to a deterministic location return (sparsity_pattern == other.sparsity_pattern && current_row == other.current_row && - ((current_entry == other.current_entry) - || - (current_row == numbers::invalid_unsigned_int))); + ((current_row == numbers::invalid_unsigned_int) + || (current_entry == other.current_entry))); } diff --git a/tests/bits/dynamic_sparsity_pattern_iterator_04.cc b/tests/bits/dynamic_sparsity_pattern_iterator_04.cc new file mode 100644 index 0000000000..37ed68dc60 --- /dev/null +++ b/tests/bits/dynamic_sparsity_pattern_iterator_04.cc @@ -0,0 +1,137 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2004 - 2015 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// test DynamicSparsityPattern::iterator and document bug with std::vector iterators + +/* +crash: +/usr/include/c++/4.8/debug/safe_iterator.h:506:error: attempt to compare a + singular iterator to a singular iterator. + +Objects involved in the operation: +iterator "lhs" @ 0x0x7fffffffc860 { +type = N11__gnu_debug14_Safe_iteratorIN9__gnu_cxx17__normal_iteratorIPKjSt6vectorIjSaIjEEEENSt7__debug6vectorIjS6_EEEE (constant iterator); + state = singular; +} +iterator "rhs" @ 0x0x7fffffffd670 { +type = N11__gnu_debug14_Safe_iteratorIN9__gnu_cxx17__normal_iteratorIPKjSt6vectorIjSaIjEEEENSt7__debug6vectorIjS6_EEEE (constant iterator); + state = singular; +} + +backtrace: +#3 0x0000000000416c29 in __gnu_debug::operator==<__gnu_cxx::__normal_iterator > >, std::__debug::vector > > (__lhs=, __rhs=) at /usr/include/c++/4.8/debug/safe_iterator.h:503 +#4 0x000000000041075b in operator== (other=..., this=0x7fffffffc850) at /scratch/deal-git/include/deal.II/lac/dynamic_sparsity_pattern.h:743 +#5 operator== (other=..., this=0x7fffffffc850) at /scratch/deal-git/include/deal.II/lac/dynamic_sparsity_pattern.h:868 +#6 operator!= (other=..., this=0x7fffffffc850) at /scratch/deal-git/include/deal.II/lac/dynamic_sparsity_pattern.h:877 +#7 iterate (sp=...) at /scratch/deal-git/tests/bits/dynamic_sparsity_pattern_iterator_04.cc:30 +*/ + +#include "../tests.h" +#include +#include +#include + + +void iterate(DynamicSparsityPattern &sp) +{ + DynamicSparsityPattern::const_iterator i = sp.begin(); + for (; i!=sp.end(); ++i) + deallog << i->row() << ' ' << i->column() << std::endl; + + deallog << "OK" << std::endl; + + { + for (unsigned int row=0; row