In utils/geom.c around line 2234 (master cd191af), the duplicate-removal step at the end of intersect_line_with_prism looks like this:
double slist_unique[num_vertices+2];
slist_unique[0] = slist[0];
for (nv = 1; nv < num_intersections; nv++) {
if (fabs(slist[nv] - slist[nv-1]) > duplicate_tolerance*fabs(slist[nv])) {
slist_unique[num_unique_elements] = slist[nv];
num_unique_elements++;
}
}
slist = slist_unique;
num_intersections = num_unique_elements;
return num_intersections;
The dedup loop writes the deduped values into a local VLA slist_unique, then does slist = slist_unique; and returns the new count. But slist is a pass-by-value pointer parameter, reassigning it just rebinds the local variable. The caller's buffer is never touched, and slist_unique is destroyed when the function returns. So the caller gets the right count but reads the wrong values: they end up looking at the first count entries of the sorted-but-undeduped buffer.
The fix is a one-liner:
- slist = slist_unique;
+ memcpy(slist, slist_unique, num_unique_elements * sizeof(double));
In
utils/geom.caround line 2234 (mastercd191af), the duplicate-removal step at the end ofintersect_line_with_prismlooks like this:The dedup loop writes the deduped values into a local VLA
slist_unique, then doesslist = slist_unique;and returns the new count. Butslistis a pass-by-value pointer parameter, reassigning it just rebinds the local variable. The caller's buffer is never touched, andslist_uniqueis destroyed when the function returns. So the caller gets the right count but reads the wrong values: they end up looking at the firstcountentries of the sorted-but-undeduped buffer.The fix is a one-liner: