From a8de821bb8cbed53c40c15c6d536845985423b47 Mon Sep 17 00:00:00 2001 From: Nicolas Cellier Date: Tue, 21 Jan 2020 18:39:10 +0100 Subject: [PATCH] Fix issue #472 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. --- platforms/Cross/plugins/Squeak3D/b3dInit.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/platforms/Cross/plugins/Squeak3D/b3dInit.c b/platforms/Cross/plugins/Squeak3D/b3dInit.c index 1be06e0f02..2bfe23c413 100644 --- a/platforms/Cross/plugins/Squeak3D/b3dInit.c +++ b/platforms/Cross/plugins/Squeak3D/b3dInit.c @@ -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); @@ -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);