Commit 1012f680 authored by Sam Lantinga's avatar Sam Lantinga

Use SDL C functions (fixes security warnings on OpenBSD)

--HG--
branch : SDL-1.2
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%402531
parent 585eb48c
...@@ -438,7 +438,9 @@ static void create_aux_windows(_THIS) ...@@ -438,7 +438,9 @@ static void create_aux_windows(_THIS)
/* Open an input method. */ /* Open an input method. */
if (SDL_IM == NULL) { if (SDL_IM == NULL) {
char *old_locale, *old_modifiers; char *old_locale = NULL, *old_modifiers = NULL;
const char *p;
size_t n;
/* I'm not comfortable to do locale setup /* I'm not comfortable to do locale setup
here. However, we need C library locale here. However, we need C library locale
(and xlib modifiers) to be set based on the (and xlib modifiers) to be set based on the
...@@ -455,29 +457,21 @@ static void create_aux_windows(_THIS) ...@@ -455,29 +457,21 @@ static void create_aux_windows(_THIS)
/* Save the current (application program's) /* Save the current (application program's)
locale settings. */ locale settings. */
old_locale = setlocale(LC_ALL, NULL); p = setlocale(LC_ALL, NULL);
old_modifiers = XSetLocaleModifiers(NULL); if ( p ) {
if (old_locale == NULL || old_modifiers == NULL) { n = SDL_strlen(p)+1;
/* The specs guarantee that the query old_locale = SDL_stack_alloc(char, n);
calls to above functions never if ( old_locale ) {
fail, so we should never come SDL_strlcpy(old_locale, p, n);
here. */ }
SDL_SetError("failed to retreive current locale settings"); }
old_locale = NULL; p = XSetLocaleModifiers(NULL);
old_modifiers = NULL; if ( p ) {
} else { n = SDL_strlen(p)+1;
/* Save retreived values in our own old_modifiers = SDL_stack_alloc(char, n);
storage, since they may be if ( old_modifiers ) {
overwritten by the successive calls SDL_strlcpy(old_modifiers, p, n);
to }
setlocale/XSetLocaleModifiers. */
char const *p;
p = old_locale;
old_locale = SDL_malloc(strlen(p) + 1);
strcpy(old_locale, p);
p = old_modifiers;
old_modifiers = SDL_malloc(strlen(p) + 1);
strcpy(old_modifiers, p);
} }
/* Fetch the user's preferences and open the /* Fetch the user's preferences and open the
...@@ -489,15 +483,17 @@ static void create_aux_windows(_THIS) ...@@ -489,15 +483,17 @@ static void create_aux_windows(_THIS)
/* Restore the application's locale settings /* Restore the application's locale settings
so that we don't break the application's so that we don't break the application's
expected behaviour. */ expected behaviour. */
if (old_locale != NULL && old_modifiers != NULL) { if ( old_locale ) {
/* We need to restore the C library /* We need to restore the C library
locale first, since the locale first, since the
interpretation of the X modifier interpretation of the X modifier
may depend on it. */ may depend on it. */
setlocale(LC_ALL, old_locale); setlocale(LC_ALL, old_locale);
SDL_free(old_locale); SDL_stack_free(old_locale);
}
if ( old_modifiers ) {
XSetLocaleModifiers(old_modifiers); XSetLocaleModifiers(old_modifiers);
SDL_free(old_modifiers); SDL_stack_free(old_modifiers);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment