mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 01:34:11 +03:00
virCommandAddArgBuffer: Simplify clearing of @buf
Get the buffer contents into a temporary variable with automatic clearing so that the error branches don't have to reset the buffer. Additionally handle the NULL string case before assignment. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
parent
13a9075cea
commit
e3a792a39b
@ -1550,21 +1550,21 @@ virCommandAddArg(virCommandPtr cmd, const char *val)
|
||||
void
|
||||
virCommandAddArgBuffer(virCommandPtr cmd, virBufferPtr buf)
|
||||
{
|
||||
if (!cmd || cmd->has_error) {
|
||||
virBufferFreeAndReset(buf);
|
||||
g_autofree char *str = virBufferContentAndReset(buf);
|
||||
|
||||
if (!cmd || cmd->has_error)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!str)
|
||||
str = g_strdup("");
|
||||
|
||||
/* Arg plus trailing NULL. */
|
||||
if (VIR_RESIZE_N(cmd->args, cmd->maxargs, cmd->nargs, 1 + 1) < 0) {
|
||||
cmd->has_error = ENOMEM;
|
||||
virBufferFreeAndReset(buf);
|
||||
return;
|
||||
}
|
||||
|
||||
cmd->args[cmd->nargs] = virBufferContentAndReset(buf);
|
||||
if (!cmd->args[cmd->nargs])
|
||||
cmd->args[cmd->nargs] = g_strdup("");
|
||||
cmd->args[cmd->nargs] = g_steal_pointer(&str);
|
||||
cmd->nargs++;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user