From patchwork Thu Jun 8 21:13:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 103417 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp2632962qgd; Thu, 8 Jun 2017 14:16:18 -0700 (PDT) X-Received: by 10.99.185.67 with SMTP id v3mr9690143pgo.189.1496956577954; Thu, 08 Jun 2017 14:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496956577; cv=none; d=google.com; s=arc-20160816; b=cGE4N39bLcL/GWNSVahnv/0Z8PhrdBXyrmR6lKOpLWQ/5G3NfEM9zWmmmNCEqJ/SBS WDokp+fITsmttyyp+zv9oY4lQwnUamNHA3nI1/srh57ZbEKpUiyPuwLrIQoruEwVoqmX MvWPdAwIpcr6CscaYDGLP816Nr/w/G5E4yPi7GOgpEUxBirkepZPurTst+NC0Ng9N5GM tXqe3gMophXqMzzCtzoqoAg0HUZ83Cfk/EjATk71FY1X4NV05iMT+FMtuls5BZTFuHOb hevJ4kZ1ImOnf266xkLjxskF+VmxTw4lnbFZIwU4otLx58M9vJgX8jWhCdgJlh/X1GkT ll6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from:delivered-to :sender:list-help:list-post:list-archive:list-subscribe :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=Sy7eyYDM8fz4qIIIXSj9U7+Ulqz3q0JJCIhQmgt1ZBU=; b=riukcjxha/qeFft7ZH7PdNJhlnIMrjtWX7U4BGJFyLfBToMWQZ6jlTeTHYmfgp5zTX buIWNR9Pv6H+h7r5hIENSch3f9jvNQCmNSecy0AbdFdYi9fLSR1SH1/OMWtif/KGZfsi hSypqvlDjkI9KVKtDKGle/3khKBhC/Q096Xi2zxzgCO28hO6LXS+Gvlhwm70/La7uhIj NvJnQiw06BNJp4kWsbASSTJK+OxS0RhiZgcv5O+jddScKDKcBzu6pCYYuEkpRnMlYPi2 69T/F+wDfDReDCCeFoytEE2TTG7GYzHmSldAMz0bRaDmqkgFfK6PZuodCJ7ZmyVpTZcx vdjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of libc-alpha-return-80211-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-80211-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id x4si5389735pfd.40.2017.06.08.14.16.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Jun 2017 14:16:17 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-80211-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of libc-alpha-return-80211-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-80211-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=bOnR4AtQFQbsCVW2lqm3zW5M69MetS0 EabEaaUe7q6yJJnwMwH6tUO1xDUNSkyZdC0RwZ/lx/MExTWC9fnam7ngJF3HhQTC SmE2DkgL/TqV+c24Lb8dh3Bjugy5bxsUz+SXf8scIz+Oh+GZ49gbyJ/84jwdl57U +mg2LqC6zP+A= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=ZEtDywxSm8AWlXGr8qhHc1oWsl4=; b=OoGuV xf0cW8+98fCvxek13YdBsXfsksTHYwRqzFOs2D8Sum+41yeZXBvXhV4KWqE1Likw 0SOWmAhnrUn6+3b3++4S42qjYJquahv/76gpXYP1TlxAnExtFIJI0Y0e2ejCqT01 VquAO42vhJ+ryc8El2FNNyAZGA+lCE28JdV44I= Received: (qmail 40133 invoked by alias); 8 Jun 2017 21:14:12 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 40022 invoked by uid 89); 8 Jun 2017 21:14:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-27.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt0-f181.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Sy7eyYDM8fz4qIIIXSj9U7+Ulqz3q0JJCIhQmgt1ZBU=; b=iau0Ixhe56uFTivuh8SrIg7oy26JI2C7f9/W3qTs858rtZLJBO5TyigRRoGNaHWUaa Dz4aRiuqieRn7Du6q3+1r3aCNRnU6wugmUrgJpg9vRUTiwyTgqG8khf9hDlvjtlkxlM2 z7jDgy6J6uUSbOKA5cxNhMGuTsSkQDbKip4tNB26RoWAgPl41GaUErsInBgWSszcXbBL CJAB44XSXayBgQceo/CoSbzABtU4K9l3aQxEmO4IFgSsUzLlZzyeTy3/+qX0us6WuRiw shx3XlIVvdXK+62Spz6RxlAu2mBZltb5wfYzweyXsBPRoV06WoTZmxnpaQGTUGTPkAxo AFtw== X-Gm-Message-State: AODbwcBkLxsyOeeYkaQmUPv0P3myUd1e0eXMSbQ9yA8T+suvhSZW6yte PcKcP6BLv8H+r+sF/O6kMg== X-Received: by 10.55.40.66 with SMTP id o63mr41957488qkh.133.1496956452155; Thu, 08 Jun 2017 14:14:12 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 12/17] posix: Remove alloca usage on glob dirname Date: Thu, 8 Jun 2017 18:13:26 -0300 Message-Id: <1496956411-25594-13-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1496956411-25594-1-git-send-email-adhemerval.zanella@linaro.org> References: <1496956411-25594-1-git-send-email-adhemerval.zanella@linaro.org> This patch replaces the alloca/malloc usage for dirname creation by the char_array struct. Checked on x86_64-linux-gnu. * posix/glob.c (glob_in_dir): Remove alloca usage for fullname. --- posix/glob.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) -- 2.7.4 diff --git a/posix/glob.c b/posix/glob.c index c83feb4..beeb639 100644 --- a/posix/glob.c +++ b/posix/glob.c @@ -1272,7 +1272,6 @@ glob_in_dir (const char *pattern, const char *directory, int flags, int (*errfunc) (const char *, int), glob_t *pglob, size_t alloca_used) { - size_t dirlen = strlen (directory); void *stream = NULL; struct globnames { @@ -1312,33 +1311,24 @@ glob_in_dir (const char *pattern, const char *directory, int flags, struct stat st; struct_stat64 st64; } ust; - size_t patlen = strlen (pattern); - size_t fullsize; - bool alloca_fullname - = (! size_add_wrapv (dirlen + 1, patlen + 1, &fullsize) - && glob_use_alloca (alloca_used, fullsize)); - char *fullname; - if (alloca_fullname) - fullname = alloca_account (fullsize, alloca_used); - else + struct char_array fullname; + + if (!char_array_init_str (&fullname, directory) + || !char_array_append_str (&fullname, "/") + || !char_array_append_str (&fullname, pattern)) { - fullname = malloc (fullsize); - if (fullname == NULL) - return GLOB_NOSPACE; + char_array_free (&fullname); + return GLOB_NOSPACE; } - mempcpy (mempcpy (mempcpy (fullname, directory, dirlen), - "/", 1), - pattern, patlen + 1); if ((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0) - ? (*pglob->gl_lstat) (fullname, &ust.st) - : __lstat64 (fullname, &ust.st64)) == 0) + ? (*pglob->gl_lstat) (char_array_str (&fullname), &ust.st) + : __lstat64 (char_array_str (&fullname), &ust.st64)) == 0) /* We found this file to be existing. Now tell the rest of the function to copy this name into the result. */ flags |= GLOB_NOCHECK; - if (__glibc_unlikely (!alloca_fullname)) - free (fullname); + char_array_free (&fullname); } else {