Bug in vector.hpp

Peter Kümmel <[email protected]>
Newsgroups gmane.comp.gnu.aspell.devel
Message-ID <[email protected]>
std::vector::end() returns an iterator that
points just beyond the end of the vector.

So &*thin->end() is no valid code, because
it is a out of bound access.

std::vector::back() returns a reference to
the last element and a pointer to the last
element is: &back().

See attached patch.

Peter

_______________________________________________
Aspell-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/aspell-devel
vector.diff (text/plain, 862 B)
Index: common/vector.hpp
===================================================================
RCS file: /sources/aspell/aspell/common/vector.hpp,v
retrieving revision 1.15
diff -u -b -B -r1.15 vector.hpp
--- common/vector.hpp	3 May 2005 05:08:19 -0000	1.15
+++ common/vector.hpp	30 Aug 2006 17:30:10 -0000
@@ -47,13 +47,13 @@
     }
     T * data() {return &*this->begin();}
     T * data(int pos) {return &*this->begin() + pos;}
-    T * data_end() {return &*this->end();}
+    T * data_end() {return &this->back();}
 
     T * pbegin() {return &*this->begin();}
-    T * pend()   {return &*this->end();}
+    T * pend()   {return &this->back();}
 
     const T * pbegin() const {return &*this->begin();}
-    const T * pend()   const {return &*this->end();}
+    const T * pend()   const {return &this->back();}
 
     template <typename U>
     U * datap() {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.