[PATCH] examples: If parameters count is zero we have nothing to do

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The virDomainGetCPUStats() API contract permits nparams ==
0. print_cpu_usage() assumes nparams > 0 because the domtop example
application isn't very useful if there are no statistics. Explicitly
error out to avoid potentially using the local variable pos
uninitialized.

Reviewed-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxxxxxxx>
Reviewed-by: Sascha Silbe <silbe@xxxxxxxxxxxxxxxxxx>
Reviewed-by: Bjoern Walk <bwalk@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Marc Hartmayer <mhartmay@xxxxxxxxxxxxxxxxxx>
---
 examples/domtop/domtop.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/examples/domtop/domtop.c b/examples/domtop/domtop.c
index 2283994..f8e250b 100644
--- a/examples/domtop/domtop.c
+++ b/examples/domtop/domtop.c
@@ -203,6 +203,11 @@ print_cpu_usage(const char *dom_name,
     size_t nparams = now_nparams;
     bool delim = false;
 
+    if (nparams == 0) {
+        ERROR("parameter count is zero");
+        return;
+    }
+
     if (then_nparams != now_nparams) {
         /* this should not happen (TM) */
         ERROR("parameters counts don't match");
-- 
2.5.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]