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

[Xen-changelog] [xen master] xenbaked.c: Avoid divide by zero issue



commit 2e3a96810a37c0e58e9c59a5ef7439968a410c70
Author:     Joe Jin <joe.jin@xxxxxxxxxx>
AuthorDate: Wed Mar 14 10:14:03 2018 -0700
Commit:     Wei Liu <wei.liu2@xxxxxxxxxx>
CommitDate: Thu Mar 22 09:04:23 2018 +0000

    xenbaked.c: Avoid divide by zero issue
    
    xenbaked.c -> dump_stats(), run_time = time(&end_time) - time(&start_time),
    time() returns the value in seconds. If one cancels xenmon.py immediately
    after started, run_time can be zero, and then xenbaked will hit divide by
    zero fault.
    
    Signed-off-by: Joe Jin <joe.jin@xxxxxxxxxx>
    Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
    Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 tools/xenmon/xenbaked.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/xenmon/xenbaked.c b/tools/xenmon/xenbaked.c
index 3d9e0ed900..d3f940a26b 100644
--- a/tools/xenmon/xenbaked.c
+++ b/tools/xenmon/xenbaked.c
@@ -243,10 +243,12 @@ static void dump_stats(void)
     }
 
     printf("processed %d total records in %d seconds (%ld per second)\n",
-           rec_count, (int)run_time, (long)(rec_count/run_time));
+           rec_count, (int)run_time,
+           run_time ? (long)(rec_count/run_time) : 0L);
 
-    printf("woke up %d times in %d seconds (%ld per second)\n", wakeups,
-          (int) run_time, (long)(wakeups/run_time));
+    printf("woke up %d times in %d seconds (%ld per second)\n",
+           wakeups, (int) run_time,
+           run_time ? (long)(wakeups/run_time) : 0L);
 
     check_gotten_sum();
 }
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.