From patchwork Sat Oct 15 20:44:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ville Voutilainen X-Patchwork-Id: 682609 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sxGh66Cssz9s9x for ; Sun, 16 Oct 2016 07:45:41 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=sw5W64kC; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type; q=dns; s=default; b=BjlZjSd8t9ijeWP9H6 Qfmi7TrVowRTIldbobcIdXYRR3np9J9tqEIMZjqr1iqapw5EIahnfDefYp6kWhPJ 2v5sacC4moCvv+mC4yo01kObvoiomauW9Bu3LHSy8eAfXYMQa0ft+AT4fA34VdVc vzTfi+ThYfsXEaPn9AnqkOH2A= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type; s=default; bh=3x5ImbYlu3GYCP/4bmQTyaxk 670=; b=sw5W64kCWQlGD0oix3BoWT0KdlulaN1HiwSeRj+3jeUCuKnURdW/Y8zU a4hM0NROraWneSKtdmXfpoajqK8YOGfrvofmUffPMLOyMu1TuBGYf/PRVDIVXnlo FMz6ujl2xnFwrmV4uK1iAq2Qr2d7DaZRgPIjIWkh6po7Yg0fHCU= Received: (qmail 71924 invoked by alias); 15 Oct 2016 20:45:21 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 71791 invoked by uid 89); 15 Oct 2016 20:45:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=villevoutilainengmailcom, ville.voutilainen@gmail.com, allocs X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-it0-f65.google.com Received: from mail-it0-f65.google.com (HELO mail-it0-f65.google.com) (209.85.214.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 15 Oct 2016 20:44:55 +0000 Received: by mail-it0-f65.google.com with SMTP id o19so1409264ito.3; Sat, 15 Oct 2016 13:44:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=Oe9z8nELWky2rbBzwqiu1qOOlW+dCh1DJIODUHOJ5mw=; b=N5+FbossJA4y9ompAVutvT5NEzFdSkcI6NgtrTV7OlueYMzslJnINW9+WyX1/SDjjt IlK0DRjBiKUdVssKZNGsJ2RNKQ4436m+iSLZqlx3l4vxXMpIONZqfqX6DoYnT+yU2gw7 jt3mNdCIknxf5jIQzHIc1rZ+eXRiwY9Rn0oNw+trx7ilUJjlGxfUWQFUfYIQ2/fEOUtK cvI6r3Ibp1OdTc7D9ST4sMTQgU2Pp6xbZFOUwtIr7IDFLGmIvgDWiod8cb6TuVL905kV n36j2lVsQ5e4BmnZHArTCS38xgZfcOzArBd/DsoqbiGIUwn+M1CD8gkyEzaAkRbdFZpf R2BQ== X-Gm-Message-State: AA6/9Rn7VbKVdIsOe/dAcF3J1VOb1V5ubztGhaV8cKm14WmxplkYw6TYn21v1/4Lerw+NuFT/AbAyJncLx0lvw== X-Received: by 10.36.202.131 with SMTP id k125mr3275625itg.100.1476564293371; Sat, 15 Oct 2016 13:44:53 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.28.200 with HTTP; Sat, 15 Oct 2016 13:44:52 -0700 (PDT) In-Reply-To: References: From: Ville Voutilainen Date: Sat, 15 Oct 2016 23:44:52 +0300 Message-ID: Subject: Re: [v3 PATCH] Make sure the return value of malloc_allocator::allocate is zero-initialized so that checking it for non-zero works later. To: "libstdc++" , "gcc-patches@gcc.gnu.org" On 15 October 2016 at 22:44, Ville Voutilainen wrote: > 2016-10-15 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. A new patch, with small sanity tests added. 2016-10-15 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. diff --git a/libstdc++-v3/include/ext/malloc_allocator.h b/libstdc++-v3/include/ext/malloc_allocator.h index acb60a2..113c1dc 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 0000000..b59e709 --- /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; +}