diff --git a/devel/215_7.md b/devel/215_7.md new file mode 100644 index 0000000000..5fa8f37ae7 --- /dev/null +++ b/devel/215_7.md @@ -0,0 +1,17 @@ +# 215_7 Fix array out of bounds issue in graphics mode (#2944) + +## How to test +1. Insert a graphics block in Mogan (Insert -> Image -> Draw graphic). +2. Select the ellipse tool in the toolbar and draw an ellipse on the canvas (click twice to set the foci, and a third time to set a point on the boundary). +3. Switch to the selection tool and try to click directly on the ellipse or select it using a rectangular selection (box select). +4. Observe and confirm that the client no longer hangs in an infinite loop or crashes as it did before. + +## 2026/03/06 Fix out of bounds caused by `get_control_points` +### What +Fixed a program crash issue when selecting or box-selecting an ellipse. + +### Why +In the original `ellipse_rep::get_control_points`, the function informed the caller that it had 3 control points (`np=3`, two foci and one boundary point). However, the `abs` array, which represents the parameter range for each point on the curve, was hardcoded to initialize with only two elements (`array (0.0, 1.0)`). This caused an out-of-bounds access on `abs[2]` during the edge-snapping retrieval or distance calculation in the `curve_box_rep::graphical_select` function (which iterates from 0 to `np` seeking `abs[i]` and `abs[(i+1)%np]`), leading to undefined behavior and infinite loops. + +### How +Modified the initialization of `abs` in `ellipse_rep::get_control_points` within `src/Graphics/Types/curve.cpp`. Explicitly expanded the `abs` array to contain 3 elements: `abs << 0.0 << 0.5 << 1.0;`, aligning it with the number of control points returned and preventing out-of-bounds access in exterior loops. diff --git a/src/Graphics/Types/curve.cpp b/src/Graphics/Types/curve.cpp index 4604510d98..791bcc18ee 100644 --- a/src/Graphics/Types/curve.cpp +++ b/src/Graphics/Types/curve.cpp @@ -1074,7 +1074,8 @@ ellipse_rep::get_control_points (array& abs, array& pts, // 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); + abs= array (); + abs << 0.0 << 0.5 << 1.0; pts = points; rcip= cip; return N (points);