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 Netto X-Patchwork-Id: 20864 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(-) 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 {