From patchwork Mon Feb 5 13:27:34 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: 126886 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1972318ljc; Mon, 5 Feb 2018 05:29:38 -0800 (PST) X-Google-Smtp-Source: AH8x226qt8KYoKvTIrLX5qrf1atg9/gEADyRlX4fN3+fhvBy7vUuKkUshaou/AFTwG5jGHOZZ1D0 X-Received: by 10.101.96.47 with SMTP id p15mr1627674pgu.390.1517837378522; Mon, 05 Feb 2018 05:29:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517837378; cv=none; d=google.com; s=arc-20160816; b=o4QnT5fS0cIXRasLhC0lSSUktr+HlN9VGJl6gPYVKPokIBfhdyZJSeOcAslKYaqi40 DWkQJQSuhXZ4qKbCSDyU/6EyoiHamcBYAZWKqkSm2FYeQm+Fky69Ek7B9v9gZUbqg5D8 DhMIbqRsn9wCLNs8prYoAPubDEr1lBPvUejOQgfhYvpOG8oTjgx18xV6qJ8yfPoypb7Y XlotAi4sYfvs9QguEKHrKsK16uXtEUjyEXpQUpRE3K6OR8fAJ0beCbF+wqYhsg6jsDr5 iIc+qb0DaL4Cxn5gUsmX5diGRjgIQjpHa4533T9fVyVCV4esbsx6LN1aYOddB5cKgSeY i0Cw== 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=irZLf3c/ePGBZvl+NaJEsUNVXb3EC6chEqzsgu8FLoE=; b=qHA10Ar1ul2W8zedMBv2twFPgTjYcC1eG5VLv+4TSLdfLxMMgVS+ZODxoXHo3cGxe0 1VrqEGVP++wNxNvGiRBDhpFXm2nRCGd8Bqux0HEwJZy2eu2VmOOgEBSbubdWgWkggYlF osxemv7pTHU/rO0p/32CBoLW14O9rOIjE4MvGluwnFGWA8zEk5R4kLLCNjF28G77wVak XeYVKoo4QjGjvLCKt+PoZqeRP8i5EH8aYr6Bu91sAkGi/wQc8h2zATnz0d2gz2Qf39UA 720wLXFG3pIDwDQZzEc0xeyZlGdWru0Vukt3xF6a1H21dbB7OogIVx2t4pdj8EbWB9iq vsvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=VtVwkkPc; spf=pass (google.com: domain of libc-alpha-return-89975-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-89975-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 i12-v6si6937564plk.139.2018.02.05.05.29.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Feb 2018 05:29:38 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-89975-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=VtVwkkPc; spf=pass (google.com: domain of libc-alpha-return-89975-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-89975-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=N7iK/vVfs4vM6FczIKuMFHWm5re3aMJ yP7PckqLMyrPUMcqiLxTF5d7t3sE0BRWS3ckznNuzfLgqB7Segrhbctm+OinCg7u n9Uh91QWlfRpQFxErbSNb+H03xcd337rZv5mKa8SpP9Dff4ywUkg/yebC1bOT3/1 1g6SArPwnX4M= 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=Qqob+YS+yYISCtl/NU03WgfUZ/Y=; b=VtVwk kPcDClEnnHrjUukjS7kr4MoCZ7KoiL6AISyVPdNTddFbCqq4P+/zCN/tziUE5vEk 4suVnQgY4AEIR7AxCKj1WbN531EYHJp9o54PR0urrIn5sQNQvfz17veilBHVE1fa oP+tQJuteKzz46qWeuzMx+FL5hSRLxH4c2O/fc= Received: (qmail 34377 invoked by alias); 5 Feb 2018 13:28:02 -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 34232 invoked by uid 89); 5 Feb 2018 13:28:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 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=5257, consist X-HELO: mail-qt0-f195.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=irZLf3c/ePGBZvl+NaJEsUNVXb3EC6chEqzsgu8FLoE=; b=sk0ffL7PuSL0RzUA3BoLbaTlvVf8XWps+KZZq2uQGd0U8vRrrmwxDvjj6hB/qbUbbd pZkZ05cb41ctb0a8PehRs6qgno5V8gPK2l/iSlW0SRFuEBIPLYWjB9PbV06UiOoljPqT Yo4OLfmgc0oowJBIBWXxszOmsVNUNPSCuwUQ4EhlDFIT+znFyjudQRxnO/GgCLp55Xm4 hPyCnTMkaXj8DT1gY01huCPWZn1fZZ8nRzVbZWpUDOnk81ITACFvEb/A5jZUg3Ty2WPK GnzA3WhVqHwsgH7FkpvK4quHaml9Eqp4n3cH430dhTmgKfSYzaVoLQAguHTqZgntuOG+ ruiQ== X-Gm-Message-State: AKwxytcNvSN0TbP0KEif7ghsbIdZq8Smyc3Nw6qoehSBmUR1iazC6FXQ YdrUW0SnlNoOT8BbxKUxCJDJunfHRu0= X-Received: by 10.200.39.40 with SMTP id g37mr77817378qtg.169.1517837277962; Mon, 05 Feb 2018 05:27:57 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 12/12] posix: Remove VLA usage for internal fnmatch implementation Date: Mon, 5 Feb 2018 11:27:34 -0200 Message-Id: <1517837254-19399-13-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> Checked on x86_64-linux-gnu. * posix/fnmatch.c: Include char_array required files. * posix/fnmatch_loop.c (FCT): Replace VLA with char_array. Signed-off-by: Adhemerval Zanella --- ChangeLog | 3 +++ posix/fnmatch.c | 1 + posix/fnmatch_loop.c | 68 +++++++++++++++++++++++++--------------------------- 3 files changed, 36 insertions(+), 36 deletions(-) -- 2.7.4 diff --git a/posix/fnmatch.c b/posix/fnmatch.c index 9c2cff0..b94c965 100644 --- a/posix/fnmatch.c +++ b/posix/fnmatch.c @@ -35,6 +35,7 @@ #endif #include +#include /* For platform which support the ISO C amendement 1 functionality we support user defined character classes. */ diff --git a/posix/fnmatch_loop.c b/posix/fnmatch_loop.c index eadb343..831e5ba 100644 --- a/posix/fnmatch_loop.c +++ b/posix/fnmatch_loop.c @@ -493,26 +493,20 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, { int32_t table_size; const int32_t *symb_table; -# if WIDE_CHAR_VERSION - char str[c1]; - unsigned int strcnt; -# else -# define str (startp + 1) -# endif + struct char_array str; + char_array_init_empty (&str); const unsigned char *extra; int32_t idx; int32_t elem; int32_t second; int32_t hash; -# if WIDE_CHAR_VERSION /* We have to convert the name to a single-byte string. This is possible since the names consist of ASCII characters and the internal representation is UCS4. */ - for (strcnt = 0; strcnt < c1; ++strcnt) - str[strcnt] = startp[1 + strcnt]; -#endif + for (size_t strcnt = 0; strcnt < c1; ++strcnt) + char_array_append_char (&str, startp[1 + strcnt]); table_size = _NL_CURRENT_WORD (LC_COLLATE, @@ -525,7 +519,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, _NL_COLLATE_SYMB_EXTRAMB); /* Locate the character in the hashing table. */ - hash = elem_hash (str, c1); + hash = elem_hash (char_array_str (&str), c1); idx = 0; elem = hash % table_size; @@ -539,7 +533,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, if (symb_table[2 * elem] == hash && (c1 == extra[symb_table[2 * elem + 1]]) - && memcmp (str, + && memcmp (char_array_str (&str), &extra[symb_table[2 * elem + 1] + 1], c1) == 0) @@ -580,14 +574,20 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, break; if ((int32_t) c1 == wextra[idx]) - goto matched; + { + char_array_free (&str); + goto matched; + } # else for (c1 = 0; c1 < extra[idx]; ++c1) if (n[c1] != extra[1 + c1]) break; if (c1 == extra[idx]) - goto matched; + { + char_array_free (&str); + goto matched; + } # endif } @@ -608,18 +608,21 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, { /* No valid character. Match it as a single byte. */ - if (!is_range && *n == str[0]) - goto matched; + char str0 = *char_array_at (&str, 0); + if (!is_range && *n == str0) + { + char_array_free (&str); + goto matched; + } - cold = str[0]; + cold = str0; c = *p++; } - else - return FNM_NOMATCH; + char_array_free (&str); + return FNM_NOMATCH; } } else -# undef str #endif { c = FOLD (c); @@ -711,26 +714,20 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, { int32_t table_size; const int32_t *symb_table; -# if WIDE_CHAR_VERSION - char str[c1]; - unsigned int strcnt; -# else -# define str (startp + 1) -# endif + struct char_array str; + char_array_init_empty (&str); const unsigned char *extra; int32_t idx; int32_t elem; int32_t second; int32_t hash; -# if WIDE_CHAR_VERSION /* We have to convert the name to a single-byte string. This is possible since the names consist of ASCII characters and the internal representation is UCS4. */ - for (strcnt = 0; strcnt < c1; ++strcnt) - str[strcnt] = startp[1 + strcnt]; -# endif + for (size_t strcnt = 0; strcnt < c1; ++strcnt) + char_array_append_char (&str, startp[1 + strcnt]); table_size = _NL_CURRENT_WORD (LC_COLLATE, @@ -744,7 +741,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, /* Locate the character in the hashing table. */ - hash = elem_hash (str, c1); + hash = elem_hash (char_array_str (&str), c1); idx = 0; elem = hash % table_size; @@ -758,7 +755,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, if (symb_table[2 * elem] == hash && (c1 == extra[symb_table[2 * elem + 1]]) - && memcmp (str, + && memcmp (char_array_str (&str), &extra[symb_table[2 * elem + 1] + 1], c1) == 0) { @@ -800,13 +797,12 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, } else if (symb_table[2 * elem] != 0 && c1 == 1) { - cend = str[0]; + cend = *char_array_at (&str, 0); c = *p++; } - else - return FNM_NOMATCH; + char_array_free (&str); + return FNM_NOMATCH; } -# undef str } else {