]> git.draconx.ca Git - slotifier.git/commitdiff
Fix crash when input has no holes.
authorNick Bowler <nbowler@draconx.ca>
Wed, 14 Apr 2021 01:33:13 +0000 (21:33 -0400)
committerNick Bowler <nbowler@draconx.ca>
Wed, 14 Apr 2021 01:33:13 +0000 (21:33 -0400)
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.

src/slotifier.c
tests/simple.at

index b74a9ecf5112c0daa4b3bd41c1ec1b1296af5ef4..03485f5b88d37d76749560c181fca7c8faad2bbd 100644 (file)
@@ -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;
 }
index 8e28f6b24793de54ba87997f61705c622a7b899f..11c59b7bc8de9c871098eb7280fb0aa24f58998f 100644 (file)
@@ -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