When the search tree has no elements, it seems the CNearTreeObjects
function does not give a CVector with zero elements but rather a
null pointer. This results in a null dereference when that is
passed to CVectorSize, instead of 0 as expected.
Add an explicit check for this case to avoid crashing.
}
CNearTreeObjects(t, &holes);
+ if (!holes)
+ goto out;
+
for (i = 0; i < CVectorSize(holes); i++) {
gerbv_net_t *hole;
gerbv_image_delete_net(hole);
}
+out:
CNearTreeFree(&t);
return ret;
}
]])
AT_CLEANUP
+
+AT_SETUP([no holes])
+
+AT_DATA([test.cnc],
+[[M48
+INCH,TZ
+T10C0.091
+%
+T10
+X010512Y002362G85X010512Y002047
+M30
+]])
+
+AT_CHECK([slotifier test.cnc], [0],
+[[M48
+INCH,TZ
+T10C0.091
+%
+T10
+X010512Y002362G85X010512Y002047
+M30
+
+]])
+
+AT_CLEANUP