From patchwork Mon May 14 15:34:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 913048 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-477653-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="jFqg8uWT"; dkim-atps=neutral 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 40l4Wq4VGTz9s0q for ; Tue, 15 May 2018 01:35:01 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=SrcIgC9v3zP7l+dlWIjctx3Ro8/jbo26abrnabiUbZ2jYRapuT0lF CIxDNZ6MWchSKaKK3wxgKNwIv6M5h3v9JGkgHJyjMsXiPE5jYsyFyMicrYZ75Wud R2uWYtqhQWgCCKexfCKRcB0qBs0MEz8jUQrcXBCC2wAf6m5eOy736A= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=/AGODh5VIbHWskMS/56JZWctpmI=; b=jFqg8uWTfjOO16+eiMF+ KGTM5MyL1L3Ld8DNBuTbh5WyFc7MWrzonUvWx73Cf3nxih+7I5DXi+QD2CFPZYHY 5kA6rW0rtzwe7UvHxCvxeKrQlTvWg4UZeN/iank6uWJwAMifFPMvvf9JuZPueu06 45522flOqvH5UM0XBIvNIpM= Received: (qmail 48435 invoked by alias); 14 May 2018 15:34:53 -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 48409 invoked by uid 89); 14 May 2018 15:34:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=day X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 14 May 2018 15:34:51 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 97FA5AB081; Mon, 14 May 2018 15:34:50 +0000 (UTC) Received: from localhost (unknown [10.33.36.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 369C55D6B4; Mon, 14 May 2018 15:34:49 +0000 (UTC) Date: Mon, 14 May 2018 16:34:49 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR libstdc++/67554 Do not pass null pointers to memcpy Message-ID: <20180514153449.GA2976@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.2 (2017-12-15) PR libstdc++/67554 * include/bits/valarray_array.h (_Array_copy_ctor<_Tp, true>) (_Array_copier<_Tp, true>): Do not pass null pointers to memcpy. Tested powerpc64le-linux, committed to trunk. Backports to follow. There's no new test for this, as we're not able to use sanitizers in the testsuite (something I still hope to fix one day). commit cd61c4ce0bfd69065018417dfe6f3e03b2010af3 Author: Jonathan Wakely Date: Mon May 14 15:50:16 2018 +0100 PR libstdc++/67554 Do not pass null pointers to memcpy PR libstdc++/67554 * include/bits/valarray_array.h (_Array_copy_ctor<_Tp, true>) (_Array_copier<_Tp, true>): Do not pass null pointers to memcpy. diff --git a/libstdc++-v3/include/bits/valarray_array.h b/libstdc++-v3/include/bits/valarray_array.h index f1d2c43044f..07f38ed03ed 100644 --- a/libstdc++-v3/include/bits/valarray_array.h +++ b/libstdc++-v3/include/bits/valarray_array.h @@ -152,7 +152,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { inline static void _S_do_it(const _Tp* __b, const _Tp* __e, _Tp* __restrict__ __o) - { __builtin_memcpy(__o, __b, (__e - __b) * sizeof(_Tp)); } + { + if (__b) + __builtin_memcpy(__o, __b, (__e - __b) * sizeof(_Tp)); + } }; template @@ -258,7 +261,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { inline static void _S_do_it(const _Tp* __restrict__ __a, size_t __n, _Tp* __restrict__ __b) - { __builtin_memcpy(__b, __a, __n * sizeof (_Tp)); } + { + if (__n != 0) + __builtin_memcpy(__b, __a, __n * sizeof (_Tp)); + } }; // Copy a plain array __a[<__n>] into a play array __b[<>]