From: Ján Tomko Date: Thu, 20 Mar 2014 12:05:13 +0000 (+0100) Subject: Simplify the loop in virCommandRunRegex X-Git-Tag: v1.2.3-rc1~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf4fb7d9a054bf87463b4ef6b221b36de7dc0a0f;p=thirdparty%2Flibvirt.git Simplify the loop in virCommandRunRegex Do not check for border iterator values inside the loop, move the code before/after the loop instead. --- diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 4777d66c78..8a28813352 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -2840,13 +2840,11 @@ virCommandRunRegex(virCommandPtr cmd, if (!p) p = lines[k]; + ngroup = 0; for (i = 0; i < nregex; i++) { if (regexec(®[i], p, nvars[i]+1, vars, 0) != 0) break; - 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 */ @@ -2855,16 +2853,14 @@ virCommandRunRegex(virCommandPtr cmd, goto cleanup; } - /* We're matching on the last regex, so callback time */ - if (i == (nregex-1)) { - if (((*func)(groups, data)) < 0) - goto cleanup; + } + /* We've matched on the last regex, so callback time */ + if (i == nregex) { + 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]); - ngroup = 0; - } + for (j = 0; j < totgroups; j++) + VIR_FREE(groups[j]); } }