提交 2c058412 编写于 作者: J John Ferlan

util: Avoid Coverity FORWARD_NULL

Avoid a false positive since Coverity find a path in virResizeN which
could return 0 prior to the allocation of memory and thus flags a
possible NULL dereference. Instead allocate the output buffer based
on 'nparams' and only fill it partially if need be - shouldn't be too
much a waste of space. Quicker than multiple VIR_RESIZE_N calls or
two loops of STREQ's sandwiched around a single VIR_ALLOC_N using
'n' matches from a first loop to generate the 'n' addresses to return
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 848ab685
...@@ -501,21 +501,18 @@ virTypedParamsFilter(virTypedParameterPtr params, ...@@ -501,21 +501,18 @@ virTypedParamsFilter(virTypedParameterPtr params,
const char *name, const char *name,
virTypedParameterPtr **ret) virTypedParameterPtr **ret)
{ {
size_t i, alloc = 0, n = 0; size_t i, n = 0;
virCheckNonNullArgGoto(params, error); virCheckNonNullArgGoto(params, error);
virCheckNonNullArgGoto(name, error); virCheckNonNullArgGoto(name, error);
virCheckNonNullArgGoto(ret, error); virCheckNonNullArgGoto(ret, error);
*ret = NULL; if (VIR_ALLOC_N(*ret, nparams) < 0)
goto error;
for (i = 0; i < nparams; i++) { for (i = 0; i < nparams; i++) {
if (STREQ(params[i].field, name)) { if (STREQ(params[i].field, name)) {
if (VIR_RESIZE_N(*ret, alloc, n, 1) < 0)
goto error;
(*ret)[n] = &params[i]; (*ret)[n] = &params[i];
n++; n++;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册