SDL: SDL_mfijoystick.m: remove VLA, so that projects can be built with error on vla (c76a3)

From c76a31341cf7b9c35bda34f692935b5fbaacc1b4 Mon Sep 17 00:00:00 2001
From: Sylvain Becker <[EMAIL REDACTED]>
Date: Thu, 24 Nov 2022 16:07:03 +0100
Subject: [PATCH] SDL_mfijoystick.m: remove VLA, so that projects can be built
 with error on vla

---
 src/joystick/iphoneos/SDL_mfijoystick.m | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/joystick/iphoneos/SDL_mfijoystick.m b/src/joystick/iphoneos/SDL_mfijoystick.m
index 86e481067896..2ffdab5f58cc 100644
--- a/src/joystick/iphoneos/SDL_mfijoystick.m
+++ b/src/joystick/iphoneos/SDL_mfijoystick.m
@@ -956,6 +956,7 @@ @interface GCMicroGamepad (SDL)
 #endif
 
         if (controller.extendedGamepad) {
+            SDL_bool isstack;
             GCExtendedGamepad *gamepad = controller.extendedGamepad;
 
             /* Axis order matches the XInput Windows mappings. */
@@ -969,9 +970,14 @@ @interface GCMicroGamepad (SDL)
             };
 
             /* Button order matches the XInput Windows mappings. */
-            Uint8 buttons[joystick->nbuttons];
+            Uint8 *buttons = SDL_small_alloc(Uint8, joystick->nbuttons, &isstack);
             int button_count = 0;
 
+            if (buttons == NULL) {
+                SDL_OutOfMemory();
+                return;
+            }
+
             /* These buttons are part of the original MFi spec */
             buttons[button_count++] = gamepad.buttonA.isPressed;
             buttons[button_count++] = gamepad.buttonB.isPressed;
@@ -1088,12 +1094,20 @@ @interface GCMicroGamepad (SDL)
             }
 #endif /* ENABLE_MFI_SENSORS */
 
+            SDL_small_free(buttons, isstack);
         } else if (controller.gamepad) {
+            SDL_bool isstack;
             GCGamepad *gamepad = controller.gamepad;
 
             /* Button order matches the XInput Windows mappings. */
-            Uint8 buttons[joystick->nbuttons];
+            Uint8 *buttons = SDL_small_alloc(Uint8, joystick->nbuttons, &isstack);
             int button_count = 0;
+
+            if (buttons == NULL) {
+                SDL_OutOfMemory();
+                return;
+            }
+
             buttons[button_count++] = gamepad.buttonA.isPressed;
             buttons[button_count++] = gamepad.buttonB.isPressed;
             buttons[button_count++] = gamepad.buttonX.isPressed;
@@ -1108,6 +1122,8 @@ @interface GCMicroGamepad (SDL)
             for (i = 0; i < button_count; i++) {
                 SDL_PrivateJoystickButton(joystick, i, buttons[i]);
             }
+
+            SDL_small_free(buttons, isstack);
         }
 #if TARGET_OS_TV
         else if (controller.microGamepad) {