SDL: n3ds: SDL_SYS_GetPreferredLocales now handles error cases correctly.

From 3aa531000aaf9ae00d4dbe5d7f8ccb89047d7c28 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Fri, 20 Feb 2026 10:10:30 -0500
Subject: [PATCH] n3ds: SDL_SYS_GetPreferredLocales now handles error cases
 correctly.

Previously it would have reported success but not returned a valid string, and
didn't check for the (probably extremely unlikely) case of overflowing our
locale list array.
---
 src/locale/n3ds/SDL_syslocale.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/locale/n3ds/SDL_syslocale.c b/src/locale/n3ds/SDL_syslocale.c
index ab2a11de4dbd4..52e3742a590b1 100644
--- a/src/locale/n3ds/SDL_syslocale.c
+++ b/src/locale/n3ds/SDL_syslocale.c
@@ -35,10 +35,12 @@ bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen)
     static const char AVAILABLE_LOCALES[][6] = { "ja_JP", "en_US", "fr_FR", "de_DE",
                                                  "it_IT", "es_ES", "zh_CN", "ko_KR",
                                                  "nl_NL", "pt_PT", "ru_RU", "zh_TW" };
-    u8 current_locale = GetLocaleIndex();
-    if (current_locale != BAD_LOCALE) {
-        SDL_strlcpy(buf, AVAILABLE_LOCALES[current_locale], buflen);
+    const u8 current_locale = GetLocaleIndex();
+    if ((current_locale == BAD_LOCALE) || (current_locale >= SDL_arraysize(AVAILABLE_LOCALES))) {
+        return SDL_SetError("Could not obtain system locale");
     }
+
+    SDL_strlcpy(buf, AVAILABLE_LOCALES[current_locale], buflen);
     return true;
 }