mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
virsh: Resolve Coverity NEGATIVE_RETURNS
Coverity notes that after we VIR_ALLOC_N(params, nparams) a failed call to virDomainGetCPUStats could result in nparams being set to -1. In that case, the subsequent virTypedParamsFree in cleanup will pass -1 which isn't good. Use the returned value as the number of stats to display in the loop as it will be the value reported from the hypervisor and may be less than nparams which is OK Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
58252332eb
commit
be365d8dff
@ -6734,7 +6734,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
|
|||||||
{
|
{
|
||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
virTypedParameterPtr params = NULL;
|
virTypedParameterPtr params = NULL;
|
||||||
int pos, max_id, cpu = 0, show_count = -1, nparams = 0;
|
int pos, max_id, cpu = 0, show_count = -1, nparams = 0, stats_per_cpu;
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
bool show_total = false, show_per_cpu = false;
|
bool show_total = false, show_per_cpu = false;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
@ -6853,11 +6853,12 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* passing start_cpu == -1 gives us domain's total status */
|
/* passing start_cpu == -1 gives us domain's total status */
|
||||||
if ((nparams = virDomainGetCPUStats(dom, params, nparams, -1, 1, flags)) < 0)
|
if ((stats_per_cpu = virDomainGetCPUStats(dom, params, nparams,
|
||||||
|
-1, 1, flags)) < 0)
|
||||||
goto failed_stats;
|
goto failed_stats;
|
||||||
|
|
||||||
vshPrint(ctl, _("Total:\n"));
|
vshPrint(ctl, _("Total:\n"));
|
||||||
for (i = 0; i < nparams; i++) {
|
for (i = 0; i < stats_per_cpu; i++) {
|
||||||
vshPrint(ctl, "\t%-12s ", params[i].field);
|
vshPrint(ctl, "\t%-12s ", params[i].field);
|
||||||
if ((STREQ(params[i].field, VIR_DOMAIN_CPU_STATS_CPUTIME) ||
|
if ((STREQ(params[i].field, VIR_DOMAIN_CPU_STATS_CPUTIME) ||
|
||||||
STREQ(params[i].field, VIR_DOMAIN_CPU_STATS_USERTIME) ||
|
STREQ(params[i].field, VIR_DOMAIN_CPU_STATS_USERTIME) ||
|
||||||
|
Loading…
x
Reference in New Issue
Block a user