From 8469cada6f336f05338a122758afb8e42d9b2de0 Mon Sep 17 00:00:00 2001
From: Sylvain Becker <[EMAIL REDACTED]>
Date: Thu, 24 Nov 2022 15:59:08 +0100
Subject: [PATCH] Remove VLA, project can be built with error on vla
---
IMG_ImageIO.m | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/IMG_ImageIO.m b/IMG_ImageIO.m
index 0cca03e5..65089512 100644
--- a/IMG_ImageIO.m
+++ b/IMG_ImageIO.m
@@ -288,7 +288,14 @@ static CFDictionaryRef CreateHintDictionary(CFStringRef uti_string_hint)
CGColorSpaceRef base_color_space = CGColorSpaceGetBaseColorSpace(color_space);
size_t num_components = CGColorSpaceGetNumberOfComponents(base_color_space);
size_t num_entries = CGColorSpaceGetColorTableCount(color_space);
- uint8_t *entry, entries[num_components * num_entries];
+ uint8_t *entry, *entries;
+
+ entries = SDL_calloc(num_components * num_entries, sizeof(uint8_t));
+
+ if (entries == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
/* What do we do if it's not RGB? */
if (num_components != 3) {
@@ -324,6 +331,9 @@ static CFDictionaryRef CreateHintDictionary(CFStringRef uti_string_hint)
bytes += bytes_per_row;
}
}
+
+ SDL_free(entries);
+
return surface;
}
static SDL_Surface* Create_SDL_Surface_From_CGImage(CGImageRef image_ref)