Make sure the return value of malloc_allocator::allocate is zero-initialized so...

Make sure the return value of malloc_allocator::allocate
	is zero-initialized so that checking it for non-zero works
	later.
	* include/ext/malloc_allocator.h (malloc_allocator::allocate):
	Initialize the return value.
	* testsuite/ext/malloc_allocator/sanity.cc: New.

From-SVN: r241212
This commit is contained in:
Ville Voutilainen 2016-10-16 16:31:43 +03:00 committed by Ville Voutilainen
parent 9937c1eb72
commit b08c2bc7bd
3 changed files with 41 additions and 1 deletions

View file

@ -1,3 +1,12 @@
2016-10-16 Ville Voutilainen <ville.voutilainen@gmail.com>
Make sure the return value of malloc_allocator::allocate
is zero-initialized so that checking it for non-zero works
later.
* include/ext/malloc_allocator.h (malloc_allocator::allocate):
Initialize the return value.
* testsuite/ext/malloc_allocator/sanity.cc: New.
2016-10-14 Eelis van der Weegen <eelis@eelis.net>
* include/bits/stl_algo.h (shuffle): Extract two random numbers from

View file

@ -101,7 +101,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
if (__n > this->max_size())
std::__throw_bad_alloc();
pointer __ret;
pointer __ret = 0;
#if __cpp_aligned_new
#if __cplusplus > 201402L && _GLIBCXX_HAVE_ALIGNED_ALLOC
if (alignof(_Tp) > alignof(std::max_align_t))

View file

@ -0,0 +1,31 @@
// Copyright (C) 2016 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-do run { target c++11 } }
#include <map>
#include <vector>
#include <ext/malloc_allocator.h>
int main()
{
std::map<int, int, std::less<int>,
__gnu_cxx::malloc_allocator<std::pair<int, int> > > allocs;
allocs[9] = 3;
std::vector<int, __gnu_cxx::malloc_allocator<int>> vec(10);
vec[5] = 42;
}