mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-06 07:58:44 +02:00
MacOS: create_cstr_from_cfstring uses safe conversion - use CFStringGetCString
During testing with gdk-pixbuf I noticed failures during content type
to mime conversion. The root reason was the unsafe conversion used
in create_cstr_from_cfstring. The problem was addressed in commit
c60226e0a1
but that was reverted. I noticed the commit only
when I had fixed the problem. In addition I added a test to check
the content type to mime conversion on MacOS. This problem is
discussed in Bug #788936.
See: https://bugzilla.gnome.org/show_bug.cgi?id=788936
This commit is contained in:
committed by
Philip Withnall
parent
df7e4db65a
commit
2bd423c54c
@@ -171,19 +171,26 @@ create_cfstring_from_cstr (const gchar *cstr)
|
||||
return CFStringCreateWithCString (NULL, cstr, kCFStringEncodingUTF8);
|
||||
}
|
||||
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
static gchar *
|
||||
create_cstr_from_cfstring (CFStringRef str)
|
||||
{
|
||||
const gchar *cstr;
|
||||
g_return_val_if_fail (str != NULL, NULL);
|
||||
|
||||
if (str == NULL)
|
||||
return NULL;
|
||||
|
||||
cstr = CFStringGetCStringPtr (str, kCFStringEncodingUTF8);
|
||||
CFRelease (str);
|
||||
|
||||
return g_strdup (cstr);
|
||||
CFIndex length = CFStringGetLength (str);
|
||||
CFIndex maxlen = CFStringGetMaximumSizeForEncoding (length, kCFStringEncodingUTF8);
|
||||
gchar *buffer = g_malloc (maxlen + 1);
|
||||
Boolean success = CFStringGetCString (str, (char *) buffer, maxlen,
|
||||
kCFStringEncodingUTF8);
|
||||
if (success)
|
||||
return buffer;
|
||||
else
|
||||
{
|
||||
g_free (buffer);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static char *
|
||||
url_escape_hostname (const char *url)
|
||||
|
Reference in New Issue
Block a user