From: Nick Bowler Date: Wed, 14 Apr 2021 01:33:13 +0000 (-0400) Subject: Fix crash when input has no holes. X-Git-Tag: v1.2~8 X-Git-Url: https://git.draconx.ca/gitweb/slotifier.git/commitdiff_plain/edd5c230afdc7341e5a5564d9c8ee714688705fe Fix crash when input has no holes. 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. --- diff --git a/src/slotifier.c b/src/slotifier.c index b74a9ec..03485f5 100644 --- a/src/slotifier.c +++ b/src/slotifier.c @@ -333,6 +333,9 @@ static int slotify(gerbv_image_t *drill) } CNearTreeObjects(t, &holes); + if (!holes) + goto out; + for (i = 0; i < CVectorSize(holes); i++) { gerbv_net_t *hole; @@ -358,6 +361,7 @@ static int slotify(gerbv_image_t *drill) gerbv_image_delete_net(hole); } +out: CNearTreeFree(&t); return ret; } diff --git a/tests/simple.at b/tests/simple.at index 8e28f6b..11c59b7 100644 --- a/tests/simple.at +++ b/tests/simple.at @@ -85,3 +85,28 @@ M30 ]]) 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