This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR libstdc++/80893 Fix null dereference in vector<bool>


On 31/05/17 13:45 +0100, Jonathan Wakely wrote:
vector<bool> does addressof(*ptr) where ptr is returned by
allocate(n), but if n==0 that pointer might not be dereferencable.

While testing the fix I also found some bugs in the
__gnu_test::PointerBase helper that needed correcting.

	PR libstdc++/80893
	* include/bits/stl_bvector.h (vector<bool>::_M_initialize): Avoid
	null pointer dereference when size is zero.
	* testsuite/23_containers/vector/bool/80893.cc: New.
	* testsuite/util/testsuite_allocator.h (PointerBase::PointerBase):
	Add non-explicit constructor from nullptr.
	(PointerBase::derived() const): Add const-qualified overload.

Tested powerpc64le-linux, committed to trunk.

The new test fails in C++98 modes, as shown at https://gcc.gnu.org/ml/gcc-testresults/2017-06/msg01833.html

Fixed like so, committed to trunk.

commit c8315ef81030c2d3d284c2dc3d545419243216c3
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sat Jun 17 12:46:18 2017 +0100

    PR libstdc++/80893 don't run test for C++98 modes
    
    	PR libstdc++/80893
    	* testsuite/23_containers/vector/bool/80893.cc: Add { target c++11 }.

diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/80893.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/80893.cc
index 0545b38..0b0016c 100644
--- a/libstdc++-v3/testsuite/23_containers/vector/bool/80893.cc
+++ b/libstdc++-v3/testsuite/23_containers/vector/bool/80893.cc
@@ -15,6 +15,8 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
+// { dg-do run { target c++11 } }
+
 // libstdc++/80893
 
 #include <vector>

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]