git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/6] compat/regex/regexec.c: reduce scope of variables

From
Elia Pinto <gitter.spiros@gmail.com>
Date
Apr 16, 2014, 09:33 UTC
Message-ID
<1397640811-17719-3-git-send-email-gitter.spiros@gmail.com>
In-Reply-To
<1397640811-17719-1-git-send-email-gitter.spiros@gmail.com>
Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
 compat/regex/regexec.c |   15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/compat/regex/regexec.c b/compat/regex/regexec.c
index eb5e1d4..f86dbeb 100644
--- a/compat/regex/regexec.c
+++ b/compat/regex/regexec.c
@@ -1254,12 +1254,12 @@ proceed_next_node (const re_match_context_t *mctx, int nregs, regmatch_t *regs,
 		   struct re_fail_stack_t *fs)
 {
   const re_dfa_t *const dfa = mctx->dfa;
-  int i, err;
+  int err;
   if (IS_EPSILON_NODE (dfa->nodes[node].type))
     {
       re_node_set *cur_nodes = &mctx->state_log[*pidx]->nodes;
       re_node_set *edests = &dfa->edests[node];
-      int dest_node;
+      int dest_node, i;
       err = re_node_set_insert (eps_via_nodes, node);
       if (BE (err < 0, 0))
 	return -2;
@@ -1446,9 +1446,9 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch,
 
       if (idx == pmatch[0].rm_eo && cur_node == mctx->last_node)
 	{
-	  int reg_idx;
 	  if (fs)
 	    {
+	      int reg_idx;
 	      for (reg_idx = 0; reg_idx < nmatch; ++reg_idx)
 		if (pmatch[reg_idx].rm_so > -1 && pmatch[reg_idx].rm_eo == -1)
 		  break;
@@ -1818,7 +1818,6 @@ add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes,
 		       const re_node_set *candidates)
 {
   reg_errcode_t err = REG_NOERROR;
-  int i;
 
   re_dfastate_t *state = re_acquire_state (&err, dfa, dest_nodes);
   if (BE (err != REG_NOERROR, 0))
@@ -1826,6 +1825,7 @@ add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes,
 
   if (!state->inveclosure.alloc)
     {
+      int i;
       err = re_node_set_alloc (&state->inveclosure, dest_nodes->nelem);
       if (BE (err != REG_NOERROR, 0))
 	return REG_ESPACE;
@@ -3824,7 +3824,6 @@ check_node_accept_bytes (const re_dfa_t *dfa, int node_idx,
 # ifdef _LIBC
       const unsigned char *pin
 	= ((const unsigned char *) re_string_get_buffer (input) + str_idx);
-      int j;
       uint32_t nrules;
 # endif /* _LIBC */
       int match_len = 0;
@@ -3867,6 +3866,7 @@ check_node_accept_bytes (const re_dfa_t *dfa, int node_idx,
 	  for (i = 0; i < cset->ncoll_syms; ++i)
 	    {
 	      const unsigned char *coll_sym = extra + cset->coll_syms[i];
+              int j;
 	      /* Compare the length of input collating element and
 		 the length of current collating element.  */
 	      if (*coll_sym != elem_len)
@@ -4004,13 +4004,14 @@ find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len)
 
       for (idx = 0; idx < extrasize;)
 	{
-	  int mbs_cnt, found = 0;
+	  int found = 0;
 	  int32_t elem_mbs_len;
 	  /* Skip the name of collating element name.  */
 	  idx = idx + extra[idx] + 1;
 	  elem_mbs_len = extra[idx++];
 	  if (mbs_len == elem_mbs_len)
-	    {
+	    { 
+              init mbs_cnt;
 	      for (mbs_cnt = 0; mbs_cnt < elem_mbs_len; ++mbs_cnt)
 		if (extra[idx + mbs_cnt] != mbs[mbs_cnt])
 		  break;
-- 
1.7.10.4
Previous: Elia PintoNext: Elia Pinto
Message 3 of 10 in “compat/regex/regcomp.c: reduce scope of variables”
  1. 1/6 compat/regex/regcomp.c: reduce scope of variablesElia Pinto, Apr 16, 2014
  2. 2/6 compat/regex/regex_internal.c: reduce scope of variablesElia Pinto, Apr 16, 2014
  3. 3/6 compat/regex/regexec.c: reduce scope of variablesElia Pinto, Apr 16, 2014
  4. 4/6 contrib/credential/osxkeychain/git-credential-osxkeychain.c: reduce scope of variablesElia Pinto, Apr 16, 2014
  5. Erik Faye-LundApr 16, 2014
  6. 5/6 contrib/credential/wincred/git-credential-wincred.c: reduce scope of variablesElia Pinto, Apr 16, 2014
  7. Erik Faye-LundApr 16, 2014
  8. 6/6 xdiff/xprepare.c: reduce scope of variablesElia Pinto, Apr 16, 2014
  9. Erik Faye-LundApr 16, 2014
  10. Jonathan NiederApr 16, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.