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 X-Patchwork-Id: 25807 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-Google-Smtp-Source: AH8x225mu9kPF/HUu+FZAvsbyz0sTmCkVjplO+3kL3TpeL2wiKxth2ND31yBWajZI8XiCzrjqupU/A== 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(-) 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 {