[PATCH 1/5] Remove useless 'maxReg' variable

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

 



It is used to break out of the loop early if one regex does not match.
Use the 'break' statement instead.
---
 src/util/vircommand.c | 43 ++++++++++++++++++++-----------------------
 1 file changed, 20 insertions(+), 23 deletions(-)

diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 8250634..f1adb1e 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -2782,7 +2782,6 @@ virCommandRunRegex(virCommandPtr cmd,
     int err;
     regex_t *reg;
     regmatch_t *vars = NULL;
-    int maxReg = 0;
     size_t i, j, k;
     int totgroups = 0, ngroup = 0, maxvars = 0;
     char **groups;
@@ -2841,32 +2840,30 @@ virCommandRunRegex(virCommandPtr cmd,
         if (!p)
             p = lines[k];
 
-        for (i = 0; i <= maxReg && i < nregex; i++) {
-            if (regexec(&reg[i], p, nvars[i]+1, vars, 0) == 0) {
-                maxReg++;
+        for (i = 0; i < nregex; i++) {
+            if (regexec(&reg[i], p, nvars[i]+1, vars, 0) != 0)
+                break;
 
-                if (i == 0)
-                    ngroup = 0;
+            if (i == 0)
+                ngroup = 0;
 
-                /* NULL terminate each captured group in the line */
-                for (j = 0; j < nvars[i]; j++) {
-                    /* NB vars[0] is the full pattern, so we offset j by 1 */
-                    p[vars[j+1].rm_eo] = '\0';
-                    if (VIR_STRDUP(groups[ngroup++], p + vars[j+1].rm_so) < 0)
-                        goto cleanup;
-                }
+            /* NULL terminate each captured group in the line */
+            for (j = 0; j < nvars[i]; j++) {
+                /* NB vars[0] is the full pattern, so we offset j by 1 */
+                p[vars[j+1].rm_eo] = '\0';
+                if (VIR_STRDUP(groups[ngroup++], p + vars[j+1].rm_so) < 0)
+                    goto cleanup;
+            }
 
-                /* We're matching on the last regex, so callback time */
-                if (i == (nregex-1)) {
-                    if (((*func)(groups, data)) < 0)
-                        goto cleanup;
+            /* We're matching on the last regex, so callback time */
+            if (i == (nregex-1)) {
+                if (((*func)(groups, data)) < 0)
+                    goto cleanup;
 
-                    /* Release matches & restart to matching the first regex */
-                    for (j = 0; j < totgroups; j++)
-                        VIR_FREE(groups[j]);
-                    maxReg = 0;
-                    ngroup = 0;
-                }
+                /* Release matches & restart to matching the first regex */
+                for (j = 0; j < totgroups; j++)
+                    VIR_FREE(groups[j]);
+                ngroup = 0;
             }
         }
     }
-- 
1.8.3.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]