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 X-Patchwork-Id: 109891 Delivered-To: patch@linaro.org Received: by 10.182.109.195 with SMTP id hu3csp976480obb; Fri, 11 Aug 2017 07:52:56 -0700 (PDT) X-Received: by 10.98.16.194 with SMTP id 63mr13638366pfq.172.1502463176103; Fri, 11 Aug 2017 07:52:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502463176; cv=none; d=google.com; s=arc-20160816; b=PfHPgPFAbfDNPUKhiDLADj2mEBLstauLhAd88Qet4SfIrymfeBvDjKaIm1I5J5TeLp FWJR9QpJ+MTOadQhpIHARm2yUFyJcA+ER7fYpIgbtnTpq/bizti/lpu3st9rdxkO1qax +TJgj9J9t5OhhE7EZ6XPOXlOOHuMTCRfKvf5p4Gt1ckJF/vUNtfoc+21m3l4XGGRY5y9 KBUXdNK4oCl+AE156i6zAb3LHO9w/hx6hI4wCVPToVxLAPhNnz8IEEtmj30+rvAD7QhF 36DaoW57XgiEYqcEnzBbPtVHm+EcHt/6oGZk0b31ygznULQjmAiC42RgbuxDe/WVAfcE 76mw== 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=rCJaPDUQPujsejtw4TVgs8k5rX54bVQKxSEq5VcB/CI=; b=rP4T+qv2vhOVdtm+OxtdS7+/DrS3zpiWc9cCThhKCbS9oTqLAFVgLNaW1K0qv4Zm4f heYUlVwqR6lwlJ7VIIMFkm2QzkE+ch+xRw9S+e0bKVKlyy047MLC/fAQO9ihLk9nEg/3 v1Lfyc2Wkra1OPXXCWgBI9kkyB2jMiR420CKOIWTIDVCJMSe/5o5S16BJ3fdnbrSgXhz AMlIzbc7StKXDcSIBdA6B9QLoc8yhuLVpktt+WLdicPzIOId32VQk2Vytj8ntD0GJveh O/sq94LTjYoGlyzTkp3Jsx/iIF4hq1x1zWGkUcHO8aCpSKRC1JW/STNR0JP3YC+tq74l 3JKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=uBe4UUoL; spf=pass (google.com: domain of libc-alpha-return-83033-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-83033-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 u91si623297plb.1010.2017.08.11.07.52.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Aug 2017 07:52:56 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-83033-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 header.s=default header.b=uBe4UUoL; spf=pass (google.com: domain of libc-alpha-return-83033-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-83033-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=sBUMrn2CXshGPPZjG7QtVuj90jf4zMX PIXozh6LPqEvoXSK0QxG2gzqnUx6/2OO0m/BdzZly2C4PxhNP/cIGpMJrov9EENL WvKmNWvNXRuaSvmZJ6NDh9kBDZQeXcRqtoG2vyZi4/kgNqSRIeK1K5uwlkKXMIsh wsm4z0X8cF4o= 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=xOYNF4osyX6+wPZFTFGfw+Hc5OE=; b=uBe4U UoLUQ7JFuzjA5nffGRHfYFkgSY56L7+zRIbnnTyesEQ8Yog/QldnFs0d2LdhfPIk PMtaqNnSL5zCZGtvtXKJtDNnQweKrhihbv/ti8BhHLRk5B5wgxSXEcipOLaErnD/ dlHe4p7dA6FKR1ip/1i1Pc/ZKnjxNtWfRg+VaI= 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(-) -- 2.7.4 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 {