]> xenbits.xensource.com Git - libvirt.git/commitdiff
Shift the for loop over matched vars by one
authorJán Tomko <jtomko@redhat.com>
Thu, 20 Mar 2014 12:20:08 +0000 (13:20 +0100)
committerJán Tomko <jtomko@redhat.com>
Wed, 26 Mar 2014 14:06:10 +0000 (15:06 +0100)
Instead of adding one to the iterator on every use.

src/util/vircommand.c

index 0795935d99b97fb82aac3608887d9e46ee3d8f81..448f6d3b45e8105f41a7a988267ffa4a63dfdcf0 100644 (file)
@@ -2845,10 +2845,10 @@ virCommandRunRegex(virCommandPtr cmd,
             if (regexec(&reg[i], p, nvars[i]+1, vars, 0) != 0)
                 break;
 
-            for (j = 0; j < nvars[i]; j++) {
-                /* NB vars[0] is the full pattern, so we offset j by 1 */
-                if (VIR_STRNDUP(groups[ngroup++], p + vars[j+1].rm_so,
-                                vars[j+1].rm_eo - vars[j+1].rm_so) < 0)
+            /* NB vars[0] is the full pattern, so we offset j by 1 */
+            for (j = 1; j <= nvars[i]; j++) {
+                if (VIR_STRNDUP(groups[ngroup++], p + vars[j].rm_so,
+                                vars[j].rm_eo - vars[j].rm_so) < 0)
                     goto cleanup;
             }