From b08c2bc7bd54ccd43ab86bfb94c0858dd68353e1 Mon Sep 17 00:00:00 2001 From: Ville Voutilainen Date: Sun, 16 Oct 2016 16:31:43 +0300 Subject: [PATCH] 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 --- libstdc++-v3/ChangeLog | 9 ++++++ libstdc++-v3/include/ext/malloc_allocator.h | 2 +- .../testsuite/ext/malloc_allocator/sanity.cc | 31 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/ext/malloc_allocator/sanity.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 1537793bef0..fcb6a29bfd8 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2016-10-16 Ville Voutilainen + + 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 * include/bits/stl_algo.h (shuffle): Extract two random numbers from diff --git a/libstdc++-v3/include/ext/malloc_allocator.h b/libstdc++-v3/include/ext/malloc_allocator.h index acb60a2a3cf..113c1dcfe6c 100644 --- a/libstdc++-v3/include/ext/malloc_allocator.h +++ b/libstdc++-v3/include/ext/malloc_allocator.h @@ -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)) diff --git a/libstdc++-v3/testsuite/ext/malloc_allocator/sanity.cc b/libstdc++-v3/testsuite/ext/malloc_allocator/sanity.cc new file mode 100644 index 00000000000..b59e709fa1b --- /dev/null +++ b/libstdc++-v3/testsuite/ext/malloc_allocator/sanity.cc @@ -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 +// . + +// { dg-do run { target c++11 } } + +#include +#include +#include + +int main() +{ + std::map, + __gnu_cxx::malloc_allocator > > allocs; + allocs[9] = 3; + std::vector> vec(10); + vec[5] = 42; +} -- 2.30.2