Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoff Norton <grompf@sublimeintervention.com>2010-03-22 23:24:32 +0300
committerGeoff Norton <grompf@sublimeintervention.com>2010-03-22 23:24:32 +0300
commite9b4c958f13a7cee281c25e67814ab2a5eba25ce (patch)
treea78971bf15d3abe8d427379becf772c9f2992a0d
parent9535a551ab6be76fa497dd8637953d31381fa4b7 (diff)
2010-03-22 Geoff Norton <gnorton@novell.com>
* locales.c: Its possible for CFStringGetCStringPtr to return null and not convert encodings. Use CFStringGetCString instead. svn path=/trunk/mono/; revision=154012
-rw-r--r--mono/metadata/ChangeLog5
-rw-r--r--mono/metadata/locales.c31
2 files changed, 24 insertions, 12 deletions
diff --git a/mono/metadata/ChangeLog b/mono/metadata/ChangeLog
index 27b53af4f2a..b40af414be3 100644
--- a/mono/metadata/ChangeLog
+++ b/mono/metadata/ChangeLog
@@ -1,3 +1,8 @@
+2010-03-22 Geoff Norton <gnorton@novell.com>
+
+ * locales.c: Its possible for CFStringGetCStringPtr
+ to return null and not convert encodings. Use
+ CFStringGetCString instead.
Mon Mar 22 18:06:38 CET 2010 Paolo Molaro <lupus@ximian.com>
diff --git a/mono/metadata/locales.c b/mono/metadata/locales.c
index 928ce290266..ed18312270f 100644
--- a/mono/metadata/locales.c
+++ b/mono/metadata/locales.c
@@ -381,11 +381,14 @@ get_posix_locale (void)
static gchar*
get_darwin_locale (void)
{
- const gchar *darwin_locale = NULL;
- gchar *cur_locale = NULL;
- int i;
+ static gchar *darwin_locale = NULL;
CFLocaleRef locale = NULL;
CFStringRef locale_cfstr = NULL;
+ CFIndex len;
+ int i;
+
+ if (darwin_locale != NULL)
+ return g_strdup (darwin_locale);
locale = CFLocaleCopyCurrent ();
@@ -393,20 +396,24 @@ get_darwin_locale (void)
locale_cfstr = CFLocaleGetIdentifier (locale);
if (locale_cfstr) {
- darwin_locale = CFStringGetCStringPtr (locale_cfstr, kCFStringEncodingMacRoman);
-
- cur_locale = g_strdup (darwin_locale);
+ len = CFStringGetMaximumSizeForEncoding (CFStringGetLength (locale_cfstr), kCFStringEncodingMacRoman) + 1;
+ darwin_locale = (char *) malloc (len);
+ if (!CFStringGetCString (locale_cfstr, darwin_locale, len, kCFStringEncodingMacRoman)) {
+ free (darwin_locale);
+ CFRelease (locale);
+ darwin_locale = NULL;
+ return NULL;
+ }
- for (i = 0; i < strlen (cur_locale); i++)
- if (cur_locale [i] == '_')
- cur_locale [i] = '-';
+ for (i = 0; i < strlen (darwin_locale); i++)
+ if (darwin_locale [i] == '_')
+ darwin_locale [i] = '-';
}
-
CFRelease (locale);
}
- return cur_locale;
+ return g_strdup (darwin_locale);
}
#endif
@@ -416,7 +423,7 @@ get_current_locale_name (void)
gchar *locale;
gchar *corrected = NULL;
const gchar *p;
- gchar *c;
+ gchar *c;
#ifdef HOST_WIN32
locale = g_win32_getlocale ();