Bug 541645 – gtkfilechooserdefault segfaults when bookmark does not

2008-07-06  Matthias Clasen  <mclasen@redhat.com>

        Bug 541645 – gtkfilechooserdefault segfaults when bookmark does not
        contain ://

        * gtk/gtkfilechooserdefault.c (_gtk_file_chooser_label_for_file):
        Be more robust. Reported by  Jelte van der Hoek


svn path=/trunk/; revision=20787
This commit is contained in:
Matthias Clasen 2008-07-06 05:34:03 +00:00 committed by Matthias Clasen
parent 36f5e8d776
commit 128585147f
2 changed files with 39 additions and 26 deletions

View File

@ -1,3 +1,11 @@
2008-07-06 Matthias Clasen <mclasen@redhat.com>
Bug 541645 gtkfilechooserdefault segfaults when bookmark does not
contain ://
* gtk/gtkfilechooserdefault.c (_gtk_file_chooser_label_for_file):
Be more robust. Reported by Jelte van der Hoek
2008-07-06 Matthias Clasen <mclasen@redhat.com>
Bug 540917 deprecate pack_start_defaults()

View File

@ -1621,37 +1621,42 @@ _gtk_file_chooser_label_for_file (GFile *file)
uri = g_file_get_uri (file);
start = strstr (uri, "://");
start += 3;
path = strchr (start, '/');
if (start)
{
start += 3;
path = strchr (start, '/');
if (path)
end = path;
else
{
end = uri + strlen (uri);
path = "/";
}
/* strip username */
p = strchr (start, '@');
if (p && p < end)
start = p + 1;
if (path)
end = path;
p = strchr (start, ':');
if (p && p < end)
end = p;
host = g_strndup (start, end - start);
/* Translators: the first string is a path and the second string
* is a hostname. Nautilus and the panel contain the same string
* to translate.
*/
label = g_strdup_printf (_("%1$s on %2$s"), path, host);
g_free (host);
}
else
{
end = uri + strlen (uri);
path = "/";
}
/* strip username */
p = strchr (start, '@');
if (p && p < end)
{
start = p + 1;
label = g_strdup (uri);
}
p = strchr (start, ':');
if (p && p < end)
end = p;
host = g_strndup (start, end - start);
/* Translators: the first string is a path and the second string
* is a hostname. Nautilus and the panel contain the same string
* to translate.
*/
label = g_strdup_printf (_("%1$s on %2$s"), path, host);
g_free (host);
g_free (uri);
return label;