From patchwork Fri Aug 11 14:50:37 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: 22091 Received: (qmail 78382 invoked by alias); 11 Aug 2017 14:51:14 -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 76118 invoked by uid 89); 11 Aug 2017 14:51:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2215 X-HELO: mail-qk0-f172.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=rCJaPDUQPujsejtw4TVgs8k5rX54bVQKxSEq5VcB/CI=; b=mgTxFfxNFky0UlZTEPGqC3E9FoMsmgZ9brTOh3wPURFqdOX555O9gC96yKxg3w6fWR 34hyebSoSwnFZEiLEVpp+bvh/2NTK970k2RnPp30+TP8skb5FvimEBV1se00Lrq8AUBp qheJmv+uS6EduM2AxBa6SgeaTFPhL0ZjL6wmVXG6okujsNYU2WH/nc/XKBihB/k6josX GQIo5qVri8SRiv+Sf7IrLT8iqhdyLC1+cD8Svk27eZN5aAQPlqdIYDr1z9msN2sxBud7 DFilCU19XUI2Y3d70m6BXDwHlpaf3n2Rq5N10d4t3ArW3WOYHHOVUcew8oKVl4TpfU/W L9Lg== X-Gm-Message-State: AHYfb5hvbdqT8CaMOY/T5kyrBA+ltaf1Gsh3YTT0sf0icS1bYqXU4+vJ m6mS9Qug1MDqkKKSuXJfAQ== X-Received: by 10.55.154.10 with SMTP id c10mr19087860qke.197.1502463065419; Fri, 11 Aug 2017 07:51:05 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 11/18] posix: Remove alloca usage on glob dirname Date: Fri, 11 Aug 2017 11:50:37 -0300 Message-Id: <1502463044-4042-12-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1502463044-4042-1-git-send-email-adhemerval.zanella@linaro.org> References: <1502463044-4042-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. * malloc/char_array-skeleton.c (char_array_init_str): Remove unused attribute. (char_array_append_str): Likewise. --- posix/glob.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/posix/glob.c b/posix/glob.c index 1892f48..c09b347 100644 --- a/posix/glob.c +++ b/posix/glob.c @@ -1274,7 +1274,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 { @@ -1314,35 +1313,26 @@ 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_stat) (fullname, &ust.st) - : __lstat64 (fullname, &ust.st64)) + if (((__glibc_likely (flags & GLOB_ALTDIRFUNC) + ? (*pglob->gl_lstat) (char_array_str (&fullname), &ust.st) + : __lstat64 (char_array_str (&fullname), &ust.st64)) == 0) || errno == EOVERFLOW) /* 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 {