[augeas-devel] augeas: master - * src/regexp.c (regexp_union_n): insert '|' after the first non-NULL regexp

David Lutterkort lutter at fedoraproject.org
Wed Oct 21 13:35:03 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=a17bd080ed1823650a64d20b36d6ac1b1a1b1984
Commit:        a17bd080ed1823650a64d20b36d6ac1b1a1b1984
Parent:        31b606df30249b82bc9cd2c02a3298d20ab79947
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Wed Oct 21 15:22:16 2009 +0200
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Wed Oct 21 15:22:16 2009 +0200

* src/regexp.c (regexp_union_n): insert '|' after the first non-NULL regexp

We can not blindly insert a '|' after the first passed-in regexp since that
(and any number of regexps at the beginning) might be NULL. We only insert
'|' after actually copying a regexp into the result.
---
 src/regexp.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/regexp.c b/src/regexp.c
index 7286a5b..47bfa3e 100644
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -151,14 +151,16 @@ regexp_union_n(struct info *info, int n, struct regexp **r) {
         return NULL;
 
     p = pat;
+    int added = 0;
     for (int i=0; i < n; i++) {
         if (r[i] == NULL)
             continue;
-        if (i > 0)
+        if (added > 0)
             *p++ = '|';
         *p++ = '(';
         p = stpcpy(p, r[i]->pattern->str);
         *p++ = ')';
+        added += 1;
     }
     return make_regexp(info, pat);
 }




More information about the augeas-devel mailing list