Locale fix

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@15255 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2002-12-05 10:16:46 +00:00
parent b996c9bca5
commit 65d972a7a6
2 changed files with 24 additions and 8 deletions

View file

@ -1,3 +1,9 @@
2002-12-05 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSUserDefaults.m: Fix uninitialised local variable 'locale'
which was causing a crash ... not 100% sure my fix is making the code
work as intended. Could Adam please check it?
2002-12-04 Adam Fedor <fedor@gnu.org> 2002-12-04 Adam Fedor <fedor@gnu.org>
* Headers/gnustep/base/GSLocale.h: Add category arg to * Headers/gnustep/base/GSLocale.h: Add category arg to

View file

@ -435,22 +435,29 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */
} }
else if (added_locale == NO) else if (added_locale == NO)
{ {
NSString *locale; NSString *locale = nil;
#ifdef HAVE_LOCALE_H #ifdef HAVE_LOCALE_H
locale = GSSetLocale(LC_MESSAGES, nil); locale = GSSetLocale(LC_MESSAGES, nil);
#endif #endif
if (locale == nil) if (locale == nil)
continue; {
continue;
}
/* See if we can get the dictionary from i18n functions. /* See if we can get the dictionary from i18n functions.
Note that we get the dict from the current locale regardless Note that we get the dict from the current locale regardless
of what 'lang' is, since it should match anyway. */ of what 'lang' is, since it should match anyway. */
/* Also, I don't think that the i18n routines can handle more than /* Also, I don't think that the i18n routines can handle more than
one locale, but tell me if I'm wrong... */ one locale, but tell me if I'm wrong... */
if (GSLanguageFromLocale(locale)) if (GSLanguageFromLocale(locale))
lang = GSLanguageFromLocale(locale); {
lang = GSLanguageFromLocale(locale);
}
dict = GSDomainFromDefaultLocale(); dict = GSDomainFromDefaultLocale();
if (dict) if (dict != nil)
[sharedDefaults setVolatileDomain: dict forName: lang]; {
[sharedDefaults setVolatileDomain: dict forName: lang];
}
added_locale = YES; added_locale = YES;
} }
} }
@ -475,8 +482,11 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */
+ (NSArray*) userLanguages + (NSArray*) userLanguages
{ {
NSArray *currLang = nil; NSArray *currLang = nil;
NSString *locale; NSString *locale = nil;
#ifdef HAVE_LOCALE_H
locale = GSSetLocale(LC_MESSAGES, nil);
#endif
[classLock lock]; [classLock lock];
if (userLanguages != nil) if (userLanguages != nil)
{ {
@ -516,12 +526,12 @@ static BOOL setSharedDefaults = NO; /* Flag to prevent infinite recursion */
currLang currLang
= [[self standardUserDefaults] stringArrayForKey: @"NSLanguages"]; = [[self standardUserDefaults] stringArrayForKey: @"NSLanguages"];
} }
if (currLang == nil && locale != 0 && GSLanguageFromLocale(locale)) if (currLang == nil && locale != nil && GSLanguageFromLocale(locale))
{ {
currLang = [NSArray arrayWithObject: GSLanguageFromLocale(locale)]; currLang = [NSArray arrayWithObject: GSLanguageFromLocale(locale)];
} }
#ifdef __MINGW__ #ifdef __MINGW__
if (currLang == nil && locale != 0) if (currLang == nil && locale != nil)
{ {
/* Check for language as the first part of the locale string */ /* Check for language as the first part of the locale string */
NSRange under = [locale rangeOfString: @"_"]; NSRange under = [locale rangeOfString: @"_"];