From patchwork Tue Nov 21 13:55: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: 24403 Received: (qmail 44369 invoked by alias); 21 Nov 2017 13:55:47 -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 44217 invoked by uid 89); 21 Nov 2017 13:55:46 -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, KB_WAM_FROM_NAME_SINGLEWORD, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qk0-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=WMfViEd83XDR2t97Smk+CYiaqB4Y4RCB9oHJYK169Z4=; b=JN1Q5PYtp08dJSIKIBVh3Gy3gPcAqEsrH0gSZ+zFhxPtgkwUaN82T74pJPBR0zCj7B VyHrPRo1gz5X3Sb0KLMz8fcouI29rQ/3iYZQ0pzaOTo+/MbGOlK+GM04MdRJTVElFEOJ e5ub9Z04ckVMbPjNCoyFxfKklfK/ZUBSjatIMG1u8Bu3TM0ravMI98PLGR3zGvUDSj06 hcanLZBW6ptVpddWqs/OOI8iXNysxamGtKoAHUzE0uKMiUIhv+/hR7qxGfw79HfpQPe3 VBhQEYgiWzISnR8IthOCApzj/L1R32Mv1kHgckyxdg009oJ2ubmHS7Nzi+Hpt5o1lMNY KRig== X-Gm-Message-State: AJaThX5SU1tS8DQsH8+SqlRwjwH2KT86CMlAaB/GVjG2zUYAFWkA8nYa GSxfnHZ4lx1U663COJLrXRa7DLTko7g= X-Google-Smtp-Source: AGs4zMbrOemz3CrhBMX/o2ecRxtxHWQfPlXkYHXOykODcp0OGzo7zFRq5g7PwHV3NW4+QfeOpOlPmQ== X-Received: by 10.55.215.221 with SMTP id t90mr5865535qkt.226.1511272543253; Tue, 21 Nov 2017 05:55:43 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 4/8] posix: Remove alloca usage on glob dirname Date: Tue, 21 Nov 2017 11:55:26 -0200 Message-Id: <1511272530-10936-5-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1511272530-10936-1-git-send-email-adhemerval.zanella@linaro.org> References: <1511272530-10936-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(-) diff --git a/posix/glob.c b/posix/glob.c index 7c0df0b..c83954d 100644 --- a/posix/glob.c +++ b/posix/glob.c @@ -1197,7 +1197,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]; @@ -1229,32 +1228,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 {