Skip to content

Commit

Permalink
Fix issue #472
Browse files Browse the repository at this point in the history
when `i == j`, there is nothing to sort.
If we call this for the first time, there is no stack allocated by `INIT(0)`, but stack is accessed nonetheless thru `PUSH(i,j)`.
The best thing todo IMO is to return early.
  • Loading branch information
nicolas-cellier-aka-nice committed Jan 21, 2020
1 parent 22a3226 commit a8de821
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion platforms/Cross/plugins/Squeak3D/b3dInit.c
Expand Up @@ -315,6 +315,8 @@ int b3dQuickSortInitialFaces(B3DPrimitiveObject *obj, int i, int j)
int ij, k, l, n;
B3DPrimitiveVertex *di, *dj, *dij, *tt, *vtx = obj->vertices;

if( i >= j ) return B3D_NO_ERROR;

/* Keep us enough headroom */
INIT((j-i)*2);
PUSH(i,j);
Expand Down Expand Up @@ -378,7 +380,9 @@ int b3dQuickSortObjects(B3DPrimitiveObject **array, int i, int j)
{
int ij, k, l, n;
B3DPrimitiveObject *di, *dj, *dij, *tmp;


if( i >= j ) return B3D_NO_ERROR;

/* Keep us enough headroom */
INIT((j-i)*2);
PUSH(i,j);
Expand Down

0 comments on commit a8de821

Please sign in to comment.