From patchwork Mon Feb 5 13:27:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 126877 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1971255ljc; Mon, 5 Feb 2018 05:28:13 -0800 (PST) X-Google-Smtp-Source: AH8x227zloBDa58m1KslFHM22EhxFDN872+oJkATwOwcE9EQ1RgGv2+9uYhBmbxmUxYEiUWdltcX X-Received: by 2002:a17:902:1e5:: with SMTP id b92-v6mr2981460plb.144.1517837293176; Mon, 05 Feb 2018 05:28:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517837293; cv=none; d=google.com; s=arc-20160816; b=rigw1u+A3MFip9ecpe91+dhBC/GuV86welcMyKpFnKHHV0wU7Tf7+QhrIKtNSI5OtD 9T5B9Tl+/IcpqhfHa0NVvaEkAzDI2zavGGbX0RWKgcsEtj5LN4pRPqL2oeHhrDMPqz3A zycGqaWF/y0q1q9FH4I724eUysyC/DxIziyVPj05T+1SqsTrrU5aUSF6MeoMJrZJaKpA TVROWsPIH4PmtTR1TB8vyJbfdtvmDHxt/BH2RABRz8x/9QGwjshQWxAndU5YgKm5bogT +qj7NUaWJ495mowFhfjFaf9wahCG06tQXFFQHt8/eGdYptYEyiBgSldPfxtn6VLFhUEX UZ7g== 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=SSUJrWbbpI9id/8L9RFSdToPch7srdxwjRZVerMraMY=; b=VOu5Q46sb7uszpQamwe5XP5IDnwhPJI4wlSqK3E1+XK8pvguDIGPRIPQFFqGQk3CEs TrXRb5aX64rcCiNF3DH8WoGzp7m0GK3rdhs8Z2e1+gri7BCbd56nY4HrLkjJlQgM/Yvo KyReq49Lz+qUMRIazQzvvHA7Cy3wyrK7at6WHLQj0IvWYSzqvs++xIjUtehFgJTnngQO nIvnm3rPOlmeNi0PBGXF9bxrCB6S0sn6K679JAMVIUFs/A//8AaGCZyYJkObHBQNm0kt h+8vCkndhgdnJj/9Rlpdwt9whGn4+uTmj0UPRqyQsO3VLWrq/5FKRWpLFbEt3JFo5qCV /0mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=NNqGNV05; spf=pass (google.com: domain of libc-alpha-return-89966-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-89966-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 m2si4544305pfh.158.2018.02.05.05.28.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Feb 2018 05:28:13 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-89966-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=NNqGNV05; spf=pass (google.com: domain of libc-alpha-return-89966-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-89966-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=aXB/8nD/IgkVa38FhKFVm5W8ol/8Exb Q6GQgnbB7bvqpNU/tvzsn9kf/u3BEFcjz3BqXoNy1xuN1WrjRp5TuFQOsf/O2lWX dw2qyPqjxJqwq7iQm6/9H2gP43apkAbUiX23SHTHux/yYJvSO5eZquQads6WzPpP kOkSpuhsVWvQ= 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=rJRqwKrm+eQge2FmttgxJRmdlQY=; b=NNqGN V05R8UXdI5ilLlKesOLUSi/bOAD+KYqgcYqesChLeJzanOQH7PG+lwDlzK7xi5Rv JuMdrSYj29cJyeJx6kFbw/2+PvQEr34yuMGHg6egWRUSUxWWDpqJvu2wNjrFwNit mLHcY6w5vU4m9iiLn3fd+hhNRfD9ERV0vJql5U= Received: (qmail 32606 invoked by alias); 5 Feb 2018 13:27:52 -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 32436 invoked by uid 89); 5 Feb 2018 13:27:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2061, 11986 X-HELO: mail-qt0-f196.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=SSUJrWbbpI9id/8L9RFSdToPch7srdxwjRZVerMraMY=; b=HPM+Y9Gzaskis5zXsaPpDfipDuxMKw6930VorEfEpIm0iA/UHHYhBNMf73V7/KFdc5 xJM3hK8o3hnT2dXZjFKJaX1WUyILAiMa3VUkVmGv8bzxhUCN6rAYHKt2Xk0CI6eFKyAX nz1/mctcWk1Yo5ZaTCgx4mRa5t3QornEbaorK8eHhmBHvcz0ZxhcmC1lgDyLBHb/Zibm BRL7Iz7X4wUnao8VYP+rChsRJ9Quz5rN8CxOeN/QfWBF8NDv5F/ak2QAUDzkxzhzv2nP nEDFB5kOHjjHJ0OsaY9pKFgohmtzvVwtx3TnQcc7DcSlkjGpmrL/mlKiMroQBSas8ygp I79w== X-Gm-Message-State: AKwxytfLheY5B4Kd213lwYcYjvdkeJV0RIv+CWKTbizFHzkXyE0WjtC+ g1Xj3c5xhjD/n2dncwIXiPf9sUQgoN4= X-Received: by 10.237.55.132 with SMTP id j4mr32100989qtb.324.1517837267356; Mon, 05 Feb 2018 05:27:47 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 04/12] posix: Remove alloca usage on glob dirname Date: Mon, 5 Feb 2018 11:27:26 -0200 Message-Id: <1517837254-19399-5-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1517837254-19399-1-git-send-email-adhemerval.zanella@linaro.org> References: <1517837254-19399-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. Signed-off-by: Adhemerval Zanella --- ChangeLog | 2 ++ posix/glob.c | 28 +++++++++------------------- 2 files changed, 11 insertions(+), 19 deletions(-) -- 2.7.4 diff --git a/posix/glob.c b/posix/glob.c index 3e36eeb..26af331 100644 --- a/posix/glob.c +++ b/posix/glob.c @@ -1198,7 +1198,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; # define GLOBNAMES_MEMBERS(nnames) \ struct globnames *next; size_t count; char *name[nnames]; @@ -1230,32 +1229,23 @@ glob_in_dir (const char *pattern, const char *directory, int flags, } else if (meta == GLOBPAT_NONE) { - 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 (glob_lstat (pglob, flags, fullname) == 0 + if (glob_lstat (pglob, flags, char_array_str (&fullname)) == 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 {