Handle strfxrm returning -1 a little better. Problem pointed out by Takao

* glib/gunicollate.c (g_utf8_collate_key): Handle strfxrm returning
        -1 a little better. Problem pointed out by Takao Fujiwara


svn path=/trunk/; revision=7015
This commit is contained in:
Matthias Clasen 2008-06-11 19:38:35 +00:00
parent f532b61fea
commit de09a5803a
2 changed files with 24 additions and 10 deletions

View File

@ -1,3 +1,11 @@
2008-06-11 Matthias Clasen <mclasen@redhat.com>
Bug 314453 Nautilus crashes in Solaris when browsing the attached
file
* glib/gunicollate.c (g_utf8_collate_key): Handle strfxrm returning
-1 a little better. Problem pointed out by Takao Fujiwara
2008-06-11 Matthias Clasen <mclasen@redhat.com> 2008-06-11 Matthias Clasen <mclasen@redhat.com>
Bug 529321 make check fails in glib/pcre Bug 529321 make check fails in glib/pcre

View File

@ -414,12 +414,17 @@ g_utf8_collate_key (const gchar *str,
str_norm = g_utf8_normalize (str, len, G_NORMALIZE_ALL_COMPOSE); str_norm = g_utf8_normalize (str, len, G_NORMALIZE_ALL_COMPOSE);
result = NULL;
if (g_get_charset (&charset)) if (g_get_charset (&charset))
{ {
xfrm_len = strxfrm (NULL, str_norm, 0); xfrm_len = strxfrm (NULL, str_norm, 0);
if (xfrm_len >= 0 && xfrm_len < G_MAXINT - 2)
{
result = g_malloc (xfrm_len + 1); result = g_malloc (xfrm_len + 1);
strxfrm (result, str_norm, xfrm_len + 1); strxfrm (result, str_norm, xfrm_len + 1);
} }
}
else else
{ {
gchar *str_locale = g_convert (str_norm, -1, charset, "UTF-8", NULL, NULL, NULL); gchar *str_locale = g_convert (str_norm, -1, charset, "UTF-8", NULL, NULL, NULL);
@ -441,7 +446,9 @@ g_utf8_collate_key (const gchar *str,
g_free (str_locale); g_free (str_locale);
} }
else }
if (!result)
{ {
xfrm_len = strlen (str_norm); xfrm_len = strlen (str_norm);
result = g_malloc (xfrm_len + 2); result = g_malloc (xfrm_len + 2);
@ -449,7 +456,6 @@ g_utf8_collate_key (const gchar *str,
memcpy (result + 1, str_norm, xfrm_len); memcpy (result + 1, str_norm, xfrm_len);
result[xfrm_len+1] = '\0'; result[xfrm_len+1] = '\0';
} }
}
g_free (str_norm); g_free (str_norm);
#endif /* __STDC_ISO_10646__ */ #endif /* __STDC_ISO_10646__ */