live-chart icon indicating copy to clipboard operation
live-chart copied to clipboard

golden_divisors crashes when divs.size == 0

Open ogoshen opened this issue 6 months ago • 0 comments

I was clearing out chart data when it crashed. Stack trace did lead to https://github.com/lcallarec/live-chart/blob/9d34b487602919675dd78f7c91e1f27c26eb874b/src/utils.vala#L61 Gee docs do say List.last() fails on an empty list.

My solution is then:

diff --git a/src/utils.vala b/src/utils.vala
index c964e2b..1f916e8 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -53,6 +53,10 @@ namespace LiveChart {
                 }
             } 
         }
+
+        if (divs.size == 0)
+            return new Gee.ArrayList<float?>();
+
         divs.sort((a, b) => {
             return a - b;
         });

ogoshen avatar Jun 09 '25 18:06 ogoshen