提交 25c49db5 编写于 作者: J Ján Tomko

Use VIR_STRNDUP instead of modifying the matched string

上级 d223cd76
...@@ -2832,7 +2832,7 @@ virCommandRunRegex(virCommandPtr cmd, ...@@ -2832,7 +2832,7 @@ virCommandRunRegex(virCommandPtr cmd,
goto cleanup; goto cleanup;
for (k = 0; lines[k]; k++) { for (k = 0; lines[k]; k++) {
char *p = NULL; const char *p = NULL;
/* ignore any command prefix */ /* ignore any command prefix */
if (prefix) if (prefix)
...@@ -2845,11 +2845,10 @@ virCommandRunRegex(virCommandPtr cmd, ...@@ -2845,11 +2845,10 @@ virCommandRunRegex(virCommandPtr cmd,
if (regexec(&reg[i], p, nvars[i]+1, vars, 0) != 0) if (regexec(&reg[i], p, nvars[i]+1, vars, 0) != 0)
break; break;
/* NULL terminate each captured group in the line */
for (j = 0; j < nvars[i]; j++) { for (j = 0; j < nvars[i]; j++) {
/* NB vars[0] is the full pattern, so we offset j by 1 */ /* NB vars[0] is the full pattern, so we offset j by 1 */
p[vars[j+1].rm_eo] = '\0'; if (VIR_STRNDUP(groups[ngroup++], p + vars[j+1].rm_so,
if (VIR_STRDUP(groups[ngroup++], p + vars[j+1].rm_so) < 0) vars[j+1].rm_eo - vars[j+1].rm_so) < 0)
goto cleanup; goto cleanup;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册