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

[PATCH 1/6] compat/regex/regcomp.c: reduce scope of variables

From
Elia Pinto <gitter.spiros@gmail.com>
Date
Apr 16, 2014, 09:33 UTC
Message-ID
<1397640811-17719-1-git-send-email-gitter.spiros@gmail.com>
Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
 compat/regex/regcomp.c |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/compat/regex/regcomp.c b/compat/regex/regcomp.c
index 06f3088..c7da378 100644
--- a/compat/regex/regcomp.c
+++ b/compat/regex/regcomp.c
@@ -368,7 +368,6 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
       else if (type == COMPLEX_BRACKET)
 	{
 	  re_charset_t *cset = dfa->nodes[node].opr.mbcset;
-	  int i;
 
 # ifdef _LIBC
 	  /* See if we have to try all bytes which start multiple collation
@@ -380,6 +379,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
 	      if (_NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES) != 0
 		  && (cset->ncoll_syms || cset->nranges))
 		{
+		  int i;
 		  const int32_t *table = (const int32_t *)
 		    _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
 		  for (i = 0; i < SBC_MAX; ++i)
@@ -598,7 +598,7 @@ static bitset_t utf8_sb_map;
 static void
 free_dfa_content (re_dfa_t *dfa)
 {
-  int i, j;
+  int i;
 
   if (dfa->nodes)
     for (i = 0; i < dfa->nodes_len; ++i)
@@ -621,6 +621,7 @@ free_dfa_content (re_dfa_t *dfa)
   if (dfa->state_table)
     for (i = 0; i <= dfa->state_hash_mask; ++i)
       {
+	int j;
 	struct re_state_table_entry *entry = dfa->state_table + i;
 	for (j = 0; j < entry->num; ++j)
 	  {
@@ -994,7 +995,7 @@ free_workarea_compile (regex_t *preg)
 static reg_errcode_t
 create_initial_state (re_dfa_t *dfa)
 {
-  int first, i;
+  int first;
   reg_errcode_t err;
   re_node_set init_nodes;
 
@@ -1011,6 +1012,8 @@ create_initial_state (re_dfa_t *dfa)
      Then we add epsilon closures of the nodes which are the next nodes of
      the back-references.  */
   if (dfa->nbackref > 0)
+    {
+    int i;
     for (i = 0; i < init_nodes.nelem; ++i)
       {
 	int node_idx = init_nodes.elems[i];
@@ -1044,6 +1047,7 @@ create_initial_state (re_dfa_t *dfa)
 	      }
 	  }
       }
+    }
 
   /* It must be the first time to invoke acquire_state.  */
   dfa->init_state = re_acquire_state_context (&err, dfa, &init_nodes, 0);
@@ -1682,7 +1686,6 @@ static reg_errcode_t
 calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, int node, int root)
 {
   reg_errcode_t err;
-  int i;
   re_node_set eclosure;
   int ret;
   int incomplete = 0;
@@ -1708,6 +1711,8 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, int node, int root)
 
   /* Expand each epsilon destination nodes.  */
   if (IS_EPSILON_NODE(dfa->nodes[node].type))
+    {
+    int i;
     for (i = 0; i < dfa->edests[node].nelem; ++i)
       {
 	re_node_set eclosure_elem;
@@ -1741,6 +1746,7 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, int node, int root)
 	    re_node_set_free (&eclosure_elem);
 	  }
       }
+    }
 
   /* An epsilon closure includes itself.  */
   ret = re_node_set_insert (&eclosure, node);
@@ -2630,7 +2636,6 @@ build_range_exp (bitset_t sbcset, bracket_elem_t *start_elem,
 		 bracket_elem_t *end_elem)
 # endif /* not RE_ENABLE_I18N */
 {
-  unsigned int start_ch, end_ch;
   /* Equivalence Classes and Character Classes can't be a range start/end.  */
   if (BE (start_elem->type == EQUIV_CLASS || start_elem->type == CHAR_CLASS
 	  || end_elem->type == EQUIV_CLASS || end_elem->type == CHAR_CLASS,
@@ -2647,6 +2652,7 @@ build_range_exp (bitset_t sbcset, bracket_elem_t *start_elem,
 
 # ifdef RE_ENABLE_I18N
   {
+    unsigned int start_ch, end_ch;
     wchar_t wc;
     wint_t start_wc;
     wint_t end_wc;
@@ -2728,6 +2734,7 @@ build_range_exp (bitset_t sbcset, bracket_elem_t *start_elem,
 # else /* not RE_ENABLE_I18N */
   {
     unsigned int ch;
+    unsigned int start_ch, end_ch;
     start_ch = ((start_elem->type == SB_CHAR ) ? start_elem->opr.ch
 		: ((start_elem->type == COLL_SYM) ? start_elem->opr.name[0]
 		   : 0));
-- 
1.7.10.4
Next: Elia Pinto
Message 1 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.