From patchwork Sat May 28 13:12:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 627407 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 3rH3FR3XB7z9sf9 for ; Sat, 28 May 2016 23:12:11 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=YqvQbti1; 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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=EpeCCwxp/vRJRAYFmmVAJK7As+3+pQry+MRIUQh4NyohUJJqZQL1K cr9VPx51WfNE51i2rlLNY0Oqm1YtCZJfsoj0WmnVCf1omsaa8uCrQiktgpxu9lc6 GSaCJFTJzyXw9tSqeoANosDhMwh2eZlN5Gf+Xv6xnCsqQHT3QipfrQ= 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=am3OUySheO1K5o7ZRqY93hiVhL8=; b=YqvQbti1u4Y11Eoi9wtS 5bgVo3FgPLSIgtgaRBOmDtKdUVY59O+hIMxOE8vurukUqjd+pbUTgE3B8++LcOgG JG6xnsVmS5RlxLzNV+okzajxSaN6X64aiDv/T5tBXPa+IZpeHLrfevrPtyyq5d6d nxy7APDwseiRItHXmaFIrSk= Received: (qmail 101071 invoked by alias); 28 May 2016 13:12:04 -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 101050 invoked by uid 89); 28 May 2016 13:12:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-pf0-f195.google.com Received: from mail-pf0-f195.google.com (HELO mail-pf0-f195.google.com) (209.85.192.195) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sat, 28 May 2016 13:12:02 +0000 Received: by mail-pf0-f195.google.com with SMTP id c84so9117654pfc.1 for ; Sat, 28 May 2016 06:12:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=/AjJoTiPrCgu42//9SFuXkDlbYyh7IBY6QWqVEeGIHE=; b=Qiu/HQnnafet1Xxo5w7W8HNMNnCp7yY+Sr70+zutaOn64y/ZeqkrKwAC645WO6hayl lkmaFULgd6UPREcHEgfOZngbtd18hfr3Q3ihcIfFpssIT/vMUzLnKchblcbVwe/HK68/ /wpg/tDqOedbX/Jr4D7g+gDVRkkrhk6sBbXP61gQqE2iKlN3q2MvJoFbOWpUrdK+cmC4 nMWbwSzeu54uzvgGkB3Fck/WreQ/mT4TKT3JGl80XtRoPMy+2uFNhwrvcLiIse+Hmsh1 7/ozcnfhEkW/a8O64zdtPo9TP3+4g8IXaF3qORnCDCJ/MWfF2Yop0d32c9ldkWOmLWX2 UQzg== X-Gm-Message-State: ALyK8tIDGb5H9cDP/KNZ19ivDkjOOU46rC8ALzkmHE9bEHrhm3sZRrmM2BiSDK7DjU++OQ== X-Received: by 10.98.28.148 with SMTP id c142mr30809905pfc.102.1464441120434; Sat, 28 May 2016 06:12:00 -0700 (PDT) Received: from bubble.grove.modra.org (CPE-58-160-146-233.sa.bigpond.net.au. [58.160.146.233]) by smtp.gmail.com with ESMTPSA id vi6sm35366403pab.21.2016.05.28.06.11.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 May 2016 06:11:59 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 61673EA0199; Sat, 28 May 2016 22:42:23 +0930 (ACST) Date: Sat, 28 May 2016 22:42:23 +0930 From: Alan Modra To: gcc-patches@gcc.gnu.org, binutils@sourceware.org Subject: libiberty: Don't needlessly clear xmemdup allocated memory Message-ID: <20160528131223.GB18662@bubble.grove.modra.org> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes OK to apply? * xmemdup.c (xmemdup): Use xmalloc rather than xcalloc. diff --git a/libiberty/xmemdup.c b/libiberty/xmemdup.c index aa56f0b..4602afd 100644 --- a/libiberty/xmemdup.c +++ b/libiberty/xmemdup.c @@ -1,4 +1,4 @@ -/* xmemdup.c -- Duplicate a memory buffer, using xcalloc. +/* xmemdup.c -- Duplicate a memory buffer, using xmalloc. This trivial function is in the public domain. Jeff Garzik, September 1999. */ @@ -34,6 +34,8 @@ allocated, the remaining memory is zeroed. PTR xmemdup (const PTR input, size_t copy_size, size_t alloc_size) { - PTR output = xcalloc (1, alloc_size); + PTR output = xmalloc (alloc_size); + if (alloc_size > copy_size) + memset ((char *) output + copy_size, 0, alloc_size - copy_size); return (PTR) memcpy (output, input, copy_size); }