From 366f00a3d3dc6517e7dcb1bbebb887c4f795320b Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Mon, 2 May 2022 15:38:11 +0100 Subject: [PATCH] plugins: fix out of bounds read in chopper GCC complains about this when compiling with UBSan. Change-Id: I4bd8ff2b47882ab95620dc7750a9a80f823cc2ea --- apps/plugins/chopper.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/apps/plugins/chopper.c b/apps/plugins/chopper.c index 70763a1b67..392b840317 100644 --- a/apps/plugins/chopper.c +++ b/apps/plugins/chopper.c @@ -523,19 +523,18 @@ static void chopAddBlock(int x,int y,int sx,int sy, int indexOverride) static void chopAddParticle(int x,int y,int sx,int sy) { - int i=0; - - while(mParticles[i].bIsActive && i < NUMBER_OF_PARTICLES) - i++; - - if(i==NUMBER_OF_PARTICLES) - return; - - mParticles[i].bIsActive = 1; - mParticles[i].iWorldX = x; - mParticles[i].iWorldY = y; - mParticles[i].iSpeedX = sx; - mParticles[i].iSpeedY = sy; + for(int i = 0; i < NUMBER_OF_PARTICLES; ++i) + { + if(!mParticles[i].bIsActive) + { + mParticles[i].bIsActive = 1; + mParticles[i].iWorldX = x; + mParticles[i].iWorldY = y; + mParticles[i].iSpeedX = sx; + mParticles[i].iSpeedY = sy; + return; + } + } } static void chopGenerateBlockIfNeeded(void)