Skip to contentSkip to conversation

xenbaked.c: Avoid divide by zero issue

PATCH In review Joe Jin 2 participants 2 messages Mar 14, 2018 – Mar 21, 2018

lore
Share & tools
lore

Joe Jin

author
#0 lore raw

PATCH v2 1/1 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.

---
 tools/xenmon/xenbaked.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tools/xenmon/xenbaked.c +5 -3
index 3d9e0ed900..d3f940a26b 100644
@@ -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();
 }
Signature · 7 lines
2.14.3 (Apple Git-98)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v2 1/1
#1 lore raw
Quoted 7 lines · Joe Jin

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.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel