grep-commit
[Top][All Lists]
Advanced

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

grep branch, master, updated. v2.9-18-gbb85185


From: Jim Meyering
Subject: grep branch, master, updated. v2.9-18-gbb85185
Date: Sat, 20 Aug 2011 20:42:25 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grep".

The branch, master has been updated
       via  bb85185a2b32f4c35f3cf629319ca03088602144 (commit)
       via  b0edb0fc72a8d2c706f4144867b6795b49103f85 (commit)
      from  f4c4b1b107f014244142e9b8a27208a5f3ac52b5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/grep.git/commit/?id=bb85185a2b32f4c35f3cf629319ca03088602144


commit bb85185a2b32f4c35f3cf629319ca03088602144
Author: Jim Meyering <address@hidden>
Date:   Fri Aug 12 17:57:29 2011 +0200

    maint: clean up and plug a leak-on-OOM
    
    * src/dfa.c (icatalloc): Clean up; use xrealloc in place of malloc
    and realloc; remove conditionals that are unnecessary, now that
    failed allocation results in exit.
    (enlist): Use xrealloc in place of realloc; remove conditional.
    (comsubs): Avoid leak upon failed enlist call.
    (dfamust): Use xmalloc in place of malloc.
    Remove conditionals, now that icpyalloc and icatalloc never return NULL.

diff --git a/src/dfa.c b/src/dfa.c
index b1a5266..76e34a7 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -3643,20 +3643,12 @@ static char *
 icatalloc (char *old, char const *new)
 {
   char *result;
-  size_t oldsize, newsize;
-
-  newsize = (new == NULL) ? 0 : strlen(new);
-  if (old == NULL)
-    oldsize = 0;
-  else if (newsize == 0)
+  size_t oldsize = old == NULL ? 0 : strlen (old);
+  size_t newsize = new == NULL ? 0 : strlen (new);
+  if (newsize == 0)
     return old;
-  else oldsize = strlen(old);
-  if (old == NULL)
-    result = malloc(newsize + 1);
-  else
-    result = realloc(old, oldsize + newsize + 1);
-  if (result != NULL && new != NULL)
-    strcpy(result + oldsize, new);
+  result = xrealloc (old, oldsize + newsize + 1);
+  strcpy (result + oldsize, new);
   return result;
 }
 
@@ -3764,8 +3756,16 @@ comsubs (char *left, char const *right)
         }
       if (len == 0)
         continue;
-      if ((cpp = enlist(cpp, lcp, len)) == NULL)
-        break;
+      {
+        char **p = enlist (cpp, lcp, len);
+        if (p == NULL)
+          {
+            freelist (cpp);
+            cpp = NULL;
+            break;
+          }
+        cpp = p;
+      }
     }
   return cpp;
 }
@@ -3858,13 +3858,10 @@ dfamust (struct dfa *d)
     mp[i] = must0;
   for (i = 0; i <= d->tindex; ++i)
     {
-      mp[i].in = malloc(sizeof *mp[i].in);
-      mp[i].left = malloc(2);
-      mp[i].right = malloc(2);
-      mp[i].is = malloc(2);
-      if (mp[i].in == NULL || mp[i].left == NULL ||
-          mp[i].right == NULL || mp[i].is == NULL)
-        goto done;
+      mp[i].in = xmalloc(sizeof *mp[i].in);
+      mp[i].left = xmalloc(2);
+      mp[i].right = xmalloc(2);
+      mp[i].is = xmalloc(2);
       mp[i].left[0] = mp[i].right[0] = mp[i].is[0] = '\0';
       mp[i].in[0] = NULL;
     }
@@ -3971,13 +3968,8 @@ dfamust (struct dfa *d)
                 char *tp;
 
                 tp = icpyalloc(lmp->right);
-                if (tp == NULL)
-                  goto done;
                 tp = icatalloc(tp, rmp->left);
-                if (tp == NULL)
-                  goto done;
-                lmp->in = enlist(lmp->in, tp,
-                                 strlen(tp));
+                lmp->in = enlist(lmp->in, tp, strlen(tp));
                 free(tp);
                 if (lmp->in == NULL)
                   goto done;

http://git.savannah.gnu.org/cgit/grep.git/commit/?id=b0edb0fc72a8d2c706f4144867b6795b49103f85


commit bb85185a2b32f4c35f3cf629319ca03088602144
Author: Jim Meyering <address@hidden>
Date:   Fri Aug 12 17:57:29 2011 +0200

    maint: clean up and plug a leak-on-OOM
    
    * src/dfa.c (icatalloc): Clean up; use xrealloc in place of malloc
    and realloc; remove conditionals that are unnecessary, now that
    failed allocation results in exit.
    (enlist): Use xrealloc in place of realloc; remove conditional.
    (comsubs): Avoid leak upon failed enlist call.
    (dfamust): Use xmalloc in place of malloc.
    Remove conditionals, now that icpyalloc and icatalloc never return NULL.

diff --git a/src/dfa.c b/src/dfa.c
index b1a5266..76e34a7 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -3643,20 +3643,12 @@ static char *
 icatalloc (char *old, char const *new)
 {
   char *result;
-  size_t oldsize, newsize;
-
-  newsize = (new == NULL) ? 0 : strlen(new);
-  if (old == NULL)
-    oldsize = 0;
-  else if (newsize == 0)
+  size_t oldsize = old == NULL ? 0 : strlen (old);
+  size_t newsize = new == NULL ? 0 : strlen (new);
+  if (newsize == 0)
     return old;
-  else oldsize = strlen(old);
-  if (old == NULL)
-    result = malloc(newsize + 1);
-  else
-    result = realloc(old, oldsize + newsize + 1);
-  if (result != NULL && new != NULL)
-    strcpy(result + oldsize, new);
+  result = xrealloc (old, oldsize + newsize + 1);
+  strcpy (result + oldsize, new);
   return result;
 }
 
@@ -3764,8 +3756,16 @@ comsubs (char *left, char const *right)
         }
       if (len == 0)
         continue;
-      if ((cpp = enlist(cpp, lcp, len)) == NULL)
-        break;
+      {
+        char **p = enlist (cpp, lcp, len);
+        if (p == NULL)
+          {
+            freelist (cpp);
+            cpp = NULL;
+            break;
+          }
+        cpp = p;
+      }
     }
   return cpp;
 }
@@ -3858,13 +3858,10 @@ dfamust (struct dfa *d)
     mp[i] = must0;
   for (i = 0; i <= d->tindex; ++i)
     {
-      mp[i].in = malloc(sizeof *mp[i].in);
-      mp[i].left = malloc(2);
-      mp[i].right = malloc(2);
-      mp[i].is = malloc(2);
-      if (mp[i].in == NULL || mp[i].left == NULL ||
-          mp[i].right == NULL || mp[i].is == NULL)
-        goto done;
+      mp[i].in = xmalloc(sizeof *mp[i].in);
+      mp[i].left = xmalloc(2);
+      mp[i].right = xmalloc(2);
+      mp[i].is = xmalloc(2);
       mp[i].left[0] = mp[i].right[0] = mp[i].is[0] = '\0';
       mp[i].in[0] = NULL;
     }
@@ -3971,13 +3968,8 @@ dfamust (struct dfa *d)
                 char *tp;
 
                 tp = icpyalloc(lmp->right);
-                if (tp == NULL)
-                  goto done;
                 tp = icatalloc(tp, rmp->left);
-                if (tp == NULL)
-                  goto done;
-                lmp->in = enlist(lmp->in, tp,
-                                 strlen(tp));
+                lmp->in = enlist(lmp->in, tp, strlen(tp));
                 free(tp);
                 if (lmp->in == NULL)
                   goto done;

-----------------------------------------------------------------------

Summary of changes:
 src/dfa.c  |   48 ++++++++++++++++++++----------------------------
 src/main.c |    2 +-
 2 files changed, 21 insertions(+), 29 deletions(-)


hooks/post-receive
-- 
grep



reply via email to

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