Avoid signed-shift undefined behavior in EdgeGrid distance propagation (#16626)

Danielsson propagation in EdgeGrid::Grid::calculate_sdf() doubles a negative neighbor offset (-1 or -ncols) with a left shift, which is undefined behavior in C++17. Multiply by two instead.

Adds test_edge_grid.cpp, which checks signed distances inside and outside a rectangle beyond the initial edge band. Built with -fsanitize=shift, it aborts on the old code and passes with the fix.
This commit is contained in:
S H authored and GitHub committed 2026-10-19 20:44:24 -05:00
1 parent 4f63cd4051
commit 6e1d15f8a2
3 files changed
+35 -1

No files matched your search

+1 -1
View File
@@ -616,7 +616,7 @@ struct PropagateDanielssonSingleStep {
if ((signs[addr] & 2) == 0) {
float *v = &L[addr << 1];
float l = v[0] * v[0] + v[1] * v[1];
float *v2s = v + (addr_delta << 1);
float *v2s = v + 2 * addr_delta;
float v2[2] = {
v2s[0] + INCX * resolution,
v2s[1] + INCY * resolution