提交 6b39203f 编写于 作者: P Peter Krempa

util: typedparam: Optionally copy strings passed to virTypedParameterAssignValue

Some code paths already pass in pointers to strings which should be
added directly as the value of the typed parameter. To allow more
universal use of virTypedParameterAssignValue add a flag which allows to
copy the value in place.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 803d19a6
......@@ -209,7 +209,8 @@ virTypedParameterToString(virTypedParameterPtr param)
static int
virTypedParameterAssignValueVArgs(virTypedParameterPtr param,
int type,
va_list ap)
va_list ap,
bool copystr)
{
param->type = type;
switch (type) {
......@@ -232,7 +233,13 @@ virTypedParameterAssignValueVArgs(virTypedParameterPtr param,
param->value.b = !!va_arg(ap, int);
break;
case VIR_TYPED_PARAM_STRING:
param->value.s = va_arg(ap, char *);
if (copystr) {
if (VIR_STRDUP(param->value.s, va_arg(ap, char *)) < 0)
return -1;
} else {
param->value.s = va_arg(ap, char *);
}
if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0)
return -1;
break;
......@@ -265,7 +272,7 @@ virTypedParameterAssign(virTypedParameterPtr param, const char *name,
}
va_start(ap, type);
ret = virTypedParameterAssignValueVArgs(param, type, ap);
ret = virTypedParameterAssignValueVArgs(param, type, ap, false);
va_end(ap);
return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册