From 9d03ff6c1816ac52ddb3541420cec25b6eeb9d27 Mon Sep 17 00:00:00 2001
From: Susko3 <[EMAIL REDACTED]>
Date: Mon, 20 May 2024 19:38:50 +0200
Subject: [PATCH] Decrement before as the code makes more sense
---
src/events/SDL_touch.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c
index d3bf2647e050f..e47154d9bf991 100644
--- a/src/events/SDL_touch.c
+++ b/src/events/SDL_touch.c
@@ -240,15 +240,15 @@ static int SDL_DelFinger(SDL_Touch *touch, SDL_FingerID fingerid)
return -1;
}
- if (index < (touch->num_fingers - 1)) {
- // Move the deleted finger to the end of the active fingers array and shift the active fingers by one.
- // This ensures that the descriptor for the now-deleted finger is located at `touch->fingers[touch->num_fingers]` (after the decrement below)
+ --touch->num_fingers;
+ if (index < (touch->num_fingers)) {
+ // Move the deleted finger to just past the end of the active fingers array and shift the active fingers by one.
+ // This ensures that the descriptor for the now-deleted finger is located at `touch->fingers[touch->num_fingers]`
// and is ready for use in SDL_AddFinger.
SDL_Finger *deleted_finger = touch->fingers[index];
- SDL_memmove(&touch->fingers[index], &touch->fingers[index + 1], (touch->num_fingers - index - 1) * sizeof(touch->fingers[index]));
- touch->fingers[touch->num_fingers - 1] = deleted_finger;
+ SDL_memmove(&touch->fingers[index], &touch->fingers[index + 1], (touch->num_fingers - index) * sizeof(touch->fingers[index]));
+ touch->fingers[touch->num_fingers] = deleted_finger;
}
- --touch->num_fingers;
return 0;
}