Skip to contentSkip to conversation

pybootchart: Avoid divide by zero

PATCH New Richard Purdie 1 participant 1 message Sep 20, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pybootchart: Avoid divide by zero

Avoid a rare divide by zero error if there isn't data point spread.

[YOCTO #14547]

---
 scripts/pybootchartgui/pybootchartgui/draw.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
scripts/pybootchartgui/pybootchartgui/draw.py +4 -1
index 29eb7505bc2..6bac8015584 100644
@@ -267,7 +267,10 @@ def draw_chart(ctx, color, fill, chart_bounds, data, proc_tree, data_range):
     # avoid divide by zero
     if max_y == 0:
         max_y = 1.0
-    xscale = float (chart_bounds[2]) / (max_x - x_shift)
+    if (max_x - x_shift):
+        xscale = float (chart_bounds[2]) / (max_x - x_shift)
+    else:
+        xscale = float (chart_bounds[2])     
     # If data_range is given, scale the chart so that the value range in
     # data_range matches the chart bounds exactly.
     # Otherwise, scale so that the actual data matches the chart bounds.
Signature · 1 line
2.32.0