summaryrefslogtreecommitdiff
path: root/network_gui.c
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2006-05-16 21:13:41 +0000
committerDarkvater <Darkvater@openttd.org>2006-05-16 21:13:41 +0000
commit2128dbec1334548a562bde9a20ae74ca3a1857d3 (patch)
tree27a92164179fa93cc333e2b545dd4084bb2ce586 /network_gui.c
parent8fbed228a31acbdd85505a6a7e8fa662f5dfad55 (diff)
downloadopenttd-2128dbec1334548a562bde9a20ae74ca3a1857d3.tar.xz
(svn r4892) - Fix [FS#162]: SEGV when sorting an empty server list. (glx)
Diffstat (limited to 'network_gui.c')
-rw-r--r--network_gui.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/network_gui.c b/network_gui.c
index 1ad3643b8..a1ed5c386 100644
--- a/network_gui.c
+++ b/network_gui.c
@@ -151,12 +151,6 @@ static int CDECL NGameAllowedSorter(const void *a, const void *b)
return (_internal_sort_order & 1) ? -r : r;
}
-static NGameNameSortFunction* const _ngame_sorter[] = {
- &NGameNameSorter,
- &NGameClientSorter,
- &NGameAllowedSorter
-};
-
/** (Re)build the network game list as its amount has changed because
* an item has been added or deleted for example
* @param ngl list_d struct that contains all necessary information for sorting */
@@ -188,13 +182,20 @@ static void BuildNetworkGameList(network_ql_d *nqld)
static void SortNetworkGameList(network_ql_d *nqld)
{
+ static NGameNameSortFunction* const ngame_sorter[] = {
+ &NGameNameSorter,
+ &NGameClientSorter,
+ &NGameAllowedSorter
+ };
+
NetworkGameList *item;
uint i;
if (!(nqld->l.flags & VL_RESORT)) return;
+ if (nqld->l.list_length == 0) return;
_internal_sort_order = nqld->l.flags & VL_DESC;
- qsort(nqld->sort_list, nqld->l.list_length, sizeof(nqld->sort_list[0]), _ngame_sorter[nqld->l.sort_type]);
+ qsort(nqld->sort_list, nqld->l.list_length, sizeof(nqld->sort_list[0]), ngame_sorter[nqld->l.sort_type]);
/* After sorting ngl->sort_list contains the sorted items. Put these back
* into the original list. Basically nothing has changed, we are only