From: Ján Tomko Date: Thu, 20 Mar 2014 12:20:08 +0000 (+0100) Subject: Shift the for loop over matched vars by one X-Git-Tag: v1.2.3-rc1~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d4306868c7708198324cb9dbe2f2789fef68172;p=thirdparty%2Flibvirt.git Shift the for loop over matched vars by one Instead of adding one to the iterator on every use. --- diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 0795935d99..448f6d3b45 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -2845,10 +2845,10 @@ virCommandRunRegex(virCommandPtr cmd, if (regexec(®[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; }