diff options
author | Matthias Clasen <mclasen@redhat.com> | 2004-12-09 14:15:00 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2004-12-09 14:15:00 +0000 |
commit | 94ab8fe8c048997bdd49cb71eacf0f77751f7e54 (patch) | |
tree | 61bee1abf282c88b448064c11925a535091f9806 /gtk/xdgmime | |
parent | fa136147ff4e894d07cd0de3c57ef8f1e7296705 (diff) | |
download | gtk+-94ab8fe8c048997bdd49cb71eacf0f77751f7e54.tar.gz |
Make repeated calls accumulate the results, don't call qsort() on empty
2004-12-09 Matthias Clasen <mclasen@redhat.com>
* xdgmimealias.c (_xdg_mime_alias_read_from_file):
* xdgmimeparent.c (_xdg_mime_parent_read_from_file): Make
repeated calls accumulate the results, don't call qsort()
on empty arrays. (#160838, Mariano Suárez-Alvarez)
Diffstat (limited to 'gtk/xdgmime')
-rw-r--r-- | gtk/xdgmime/ChangeLog | 7 | ||||
-rw-r--r-- | gtk/xdgmime/xdgmimealias.c | 9 | ||||
-rw-r--r-- | gtk/xdgmime/xdgmimeparent.c | 9 |
3 files changed, 17 insertions, 8 deletions
diff --git a/gtk/xdgmime/ChangeLog b/gtk/xdgmime/ChangeLog index a14b625b14..bf7c0e68ba 100644 --- a/gtk/xdgmime/ChangeLog +++ b/gtk/xdgmime/ChangeLog @@ -1,3 +1,10 @@ +2004-12-09 Matthias Clasen <mclasen@redhat.com> + + * xdgmimealias.c (_xdg_mime_alias_read_from_file): + * xdgmimeparent.c (_xdg_mime_parent_read_from_file): Make + repeated calls accumulate the results, don't call qsort() + on empty arrays. (#160838, Mariano Suárez-Alvarez) + 2004-12-02 Matthias Clasen <mclasen@redhat.com> * === Released 2.5.6 === diff --git a/gtk/xdgmime/xdgmimealias.c b/gtk/xdgmime/xdgmimealias.c index 2be3d3711c..1a40e0b718 100644 --- a/gtk/xdgmime/xdgmimealias.c +++ b/gtk/xdgmime/xdgmimealias.c @@ -128,8 +128,8 @@ _xdg_mime_alias_read_from_file (XdgAliasList *list, /* FIXME: Not UTF-8 safe. Doesn't work if lines are greater than 255 chars. * Blah */ - alloc = 16; - list->aliases = malloc (alloc * sizeof (XdgAlias)); + alloc = list->n_aliases + 16; + list->aliases = realloc (list->aliases, alloc * sizeof (XdgAlias)); while (fgets (line, 255, file) != NULL) { char *sep; @@ -156,8 +156,9 @@ _xdg_mime_alias_read_from_file (XdgAliasList *list, fclose (file); - qsort (list->aliases, list->n_aliases, - sizeof (XdgAlias), alias_entry_cmp); + if (list->n_aliases > 1) + qsort (list->aliases, list->n_aliases, + sizeof (XdgAlias), alias_entry_cmp); } diff --git a/gtk/xdgmime/xdgmimeparent.c b/gtk/xdgmime/xdgmimeparent.c index f623fb2d1c..fc97b3ea2b 100644 --- a/gtk/xdgmime/xdgmimeparent.c +++ b/gtk/xdgmime/xdgmimeparent.c @@ -134,8 +134,8 @@ _xdg_mime_parent_read_from_file (XdgParentList *list, /* FIXME: Not UTF-8 safe. Doesn't work if lines are greater than 255 chars. * Blah */ - alloc = 16; - list->parents = malloc (alloc * sizeof (XdgMimeParents)); + alloc = list->n_mimes + 16; + list->parents = realloc (list->parents, alloc * sizeof (XdgMimeParents)); while (fgets (line, 255, file) != NULL) { char *sep; @@ -191,8 +191,9 @@ _xdg_mime_parent_read_from_file (XdgParentList *list, fclose (file); - qsort (list->parents, list->n_mimes, - sizeof (XdgMimeParents), &parent_entry_cmp); + if (list->n_mimes > 1) + qsort (list->parents, list->n_mimes, + sizeof (XdgMimeParents), &parent_entry_cmp); } |