[Secure Coding] master: C++: Mention front(), back() and data() member functions of vectors (7db67ea)

fweimer at fedoraproject.org fweimer at fedoraproject.org
Thu Sep 19 15:11:36 UTC 2013


Repository : http://git.fedorahosted.org/git/?p=secure-coding.git

On branch  : master

>---------------------------------------------------------------

commit 7db67ea9b35a0cb04a0b68048802950775558579
Author: Florian Weimer <fweimer at redhat.com>
Date:   Thu Sep 19 15:15:28 2013 +0200

    C++: Mention front(), back() and data() member functions of vectors


>---------------------------------------------------------------

 defensive-coding/en-US/CXX-Std.xml |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/defensive-coding/en-US/CXX-Std.xml b/defensive-coding/en-US/CXX-Std.xml
index 56e1ad0..155f70c 100644
--- a/defensive-coding/en-US/CXX-Std.xml
+++ b/defensive-coding/en-US/CXX-Std.xml
@@ -163,6 +163,15 @@
       <literal>operator[](size_type)</literal>, even though it is
       slightly more verbose.
     </para>
+    <para>
+      The <literal>front()</literal> and <literal>back()</literal>
+      member functions are undefined if a vector object is empty.  You
+      can use <literal>vec.at(0)</literal> and
+      <literal>vec.at(vec.size() - 1)</literal> as checked
+      replacements.  For an empty vector, <literal>data()</literal> is
+      defined; it returns an arbitrary pointer, but not necessarily
+      the NULL pointer.
+    </para>
   </section>
   <section id="sect-Defensive_Coding-CXX-Std-Iterators">
     <title>Iterators</title>



More information about the security mailing list