From 8f1e1979d92222a7f295d2e4356374ad14b1b875 Mon Sep 17 00:00:00 2001 From: Jia Zhang Date: Thu, 26 Mar 2026 23:20:01 -0700 Subject: [PATCH] fix: ellipse_rep::get_control_points abs array length mismatch Make abs array have one entry per control point to match the return value, consistent with all other get_control_points implementations. Previously abs had 2 elements but np=3, causing out-of-bounds access in curve_box_rep::graphical_select which led to infinite loops when drawing ellipses. --- src/Graphics/Types/curve.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Graphics/Types/curve.cpp b/src/Graphics/Types/curve.cpp index 4604510d98..18be57ac82 100644 --- a/src/Graphics/Types/curve.cpp +++ b/src/Graphics/Types/curve.cpp @@ -1067,14 +1067,13 @@ ellipse (array a, array cip, bool close) { int ellipse_rep::get_control_points (array& abs, array& pts, array& rcip) { - // According to the design, the points in the "abs" array represent the - // control points of the curve, with their corresponding parameter values on - // the curve. However, in practice, only the first and last points in the - // array will be used. Therefore, the "abs" array is used to represent the - // range of parameter values. Since we have a closed curve here, we just need - // to ensure that the starting point has a parameter value of 0 and the ending - // point has a parameter value of 1. - abs = array (0.0, 1.0); + // The "abs" array must have one entry per control point (matching the return + // value) so that graphical_select can safely index abs[0..np-1]. + // We split the parameter range [0, 1] evenly across the control points. + int n= N (points); + abs = array (n); + for (int k= 0; k < n; k++) + abs[k]= ((double) k) / ((double) (n > 1 ? n - 1 : 1)); pts = points; rcip= cip; return N (points);