bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

lib/regcomp.c patch to avoid uninitialized-variable warning


From: Paul Eggert
Subject: lib/regcomp.c patch to avoid uninitialized-variable warning
Date: Fri, 19 Aug 2005 17:10:32 -0700
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

I installed this into gnulib, and filed a glibc bug report:

2005-08-19  Paul Eggert  <address@hidden>

        * config/srclist.txt: Add glibc bug 1217 for regcomp.c.
        * lib/regcomp.c (duplicate_node): Return new index, not an error code,
        and let the caller return REG_ESPACE if out of space.  This
        removes an uninitialied-variable warning with GCC 4.0.1, and also
        avoids taking the address of a local variable.  All callers
        changed.

--- config/srclist.txt  19 Aug 2005 23:32:21 -0000      1.70
+++ config/srclist.txt  20 Aug 2005 00:07:54 -0000      1.71
@@ -95,6 +95,7 @@ $LIBCSRC/stdlib/getsubopt.c           lib gpl
 #$LIBCSRC/posix/getopt_int.h           lib gpl
 #
 # http://sources.redhat.com/bugzilla/show_bug.cgi?id=1057
+# http://sources.redhat.com/bugzilla/show_bug.cgi?id=1217
 #$LIBCSRC/posix/regcomp.c              lib gpl
 #
 $LIBCSRC/posix/regex.c                 lib gpl
--- lib/regcomp.c       8 Jul 2005 17:57:01 -0000       1.2
+++ lib/regcomp.c       20 Aug 2005 00:02:22 -0000      1.3
@@ -50,8 +50,7 @@ static reg_errcode_t link_nfa_nodes (voi
 static reg_errcode_t duplicate_node_closure (re_dfa_t *dfa, int top_org_node,
                                             int top_clone_node, int root_node,
                                             unsigned int constraint);
-static reg_errcode_t duplicate_node (int *new_idx, re_dfa_t *dfa, int org_idx,
-                                    unsigned int constraint);
+static int duplicate_node (re_dfa_t *dfa, int org_idx, unsigned int 
constraint);
 static int search_duplicated_node (re_dfa_t *dfa, int org_node,
                                   unsigned int constraint);
 static reg_errcode_t calc_eclosure (re_dfa_t *dfa);
@@ -1468,7 +1467,6 @@ duplicate_node_closure (dfa, top_org_nod
      int top_org_node, top_clone_node, root_node;
      unsigned int init_constraint;
 {
-  reg_errcode_t err;
   int org_node, clone_node, ret;
   unsigned int constraint = init_constraint;
   for (org_node = top_org_node, clone_node = top_clone_node;;)
@@ -1482,9 +1480,9 @@ duplicate_node_closure (dfa, top_org_nod
             edests of the back reference.  */
          org_dest = dfa->nexts[org_node];
          re_node_set_empty (dfa->edests + clone_node);
-         err = duplicate_node (&clone_dest, dfa, org_dest, constraint);
-         if (BE (err != REG_NOERROR, 0))
-           return err;
+         clone_dest = duplicate_node (dfa, org_dest, constraint);
+         if (BE (clone_dest == -1, 0))
+           return REG_ESPACE;
          dfa->nexts[clone_node] = dfa->nexts[org_node];
          ret = re_node_set_insert (dfa->edests + clone_node, clone_dest);
          if (BE (ret < 0, 0))
@@ -1520,9 +1518,9 @@ duplicate_node_closure (dfa, top_org_nod
                }
              constraint |= dfa->nodes[org_node].opr.ctx_type;
            }
-         err = duplicate_node (&clone_dest, dfa, org_dest, constraint);
-         if (BE (err != REG_NOERROR, 0))
-           return err;
+         clone_dest = duplicate_node (dfa, org_dest, constraint);
+         if (BE (clone_dest == -1, 0))
+           return REG_ESPACE;
          ret = re_node_set_insert (dfa->edests + clone_node, clone_dest);
          if (BE (ret < 0, 0))
            return REG_ESPACE;
@@ -1538,9 +1536,10 @@ duplicate_node_closure (dfa, top_org_nod
          if (clone_dest == -1)
            {
              /* There are no such a duplicated node, create a new one.  */
-             err = duplicate_node (&clone_dest, dfa, org_dest, constraint);
-             if (BE (err != REG_NOERROR, 0))
-               return err;
+             reg_errcode_t err;
+             clone_dest = duplicate_node (dfa, org_dest, constraint);
+             if (BE (clone_dest == -1, 0))
+               return REG_ESPACE;
              ret = re_node_set_insert (dfa->edests + clone_node, clone_dest);
              if (BE (ret < 0, 0))
                return REG_ESPACE;
@@ -1559,9 +1558,9 @@ duplicate_node_closure (dfa, top_org_nod
            }
 
          org_dest = dfa->edests[org_node].elems[1];
-         err = duplicate_node (&clone_dest, dfa, org_dest, constraint);
-         if (BE (err != REG_NOERROR, 0))
-           return err;
+         clone_dest = duplicate_node (dfa, org_dest, constraint);
+         if (BE (clone_dest == -1, 0))
+           return REG_ESPACE;
          ret = re_node_set_insert (dfa->edests + clone_node, clone_dest);
          if (BE (ret < 0, 0))
            return REG_ESPACE;
@@ -1592,27 +1591,27 @@ search_duplicated_node (dfa, org_node, c
 }
 
 /* Duplicate the node whose index is ORG_IDX and set the constraint CONSTRAINT.
-   The new index will be stored in NEW_IDX and return REG_NOERROR if succeeded,
-   otherwise return the error code.  */
+   Return the index of the new node, or -1 if insufficient storage is
+   available.  */
 
-static reg_errcode_t
-duplicate_node (new_idx, dfa, org_idx, constraint)
+static int
+duplicate_node (dfa, org_idx, constraint)
      re_dfa_t *dfa;
-     int *new_idx, org_idx;
+     int org_idx;
      unsigned int constraint;
 {
   int dup_idx = re_dfa_add_node (dfa, dfa->nodes[org_idx]);
-  if (BE (dup_idx == -1, 0))
-    return REG_ESPACE;
-  dfa->nodes[dup_idx].constraint = constraint;
-  if (dfa->nodes[org_idx].type == ANCHOR)
-    dfa->nodes[dup_idx].constraint |= dfa->nodes[org_idx].opr.ctx_type;
-  dfa->nodes[dup_idx].duplicated = 1;
-
-  /* Store the index of the original node.  */
-  dfa->org_indices[dup_idx] = org_idx;
-  *new_idx = dup_idx;
-  return REG_NOERROR;
+  if (BE (dup_idx != -1, 1))
+    {
+      dfa->nodes[dup_idx].constraint = constraint;
+      if (dfa->nodes[org_idx].type == ANCHOR)
+       dfa->nodes[dup_idx].constraint |= dfa->nodes[org_idx].opr.ctx_type;
+      dfa->nodes[dup_idx].duplicated = 1;
+
+      /* Store the index of the original node.  */
+      dfa->org_indices[dup_idx] = org_idx;
+    }
+  return dup_idx;
 }
 
 static reg_errcode_t




reply via email to

[Prev in Thread] Current Thread [Next in Thread]