From d619e899856882ac0b399c8c8b1c47ea697d313e Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 17 Apr 2007 05:39:33 +0000 Subject: [PATCH] Fixed incorrect use of the sort() function. It expects a "less than" compare function with bool return value, not a -1/0/1 returning compare function. Fixes bug #1158 (registrar crash on shutdown). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20733 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/registrar/AppInfoList.cpp | 7 ++++--- src/servers/registrar/AppInfoList.h | 2 +- src/servers/registrar/ShutdownProcess.cpp | 7 ++----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/servers/registrar/AppInfoList.cpp b/src/servers/registrar/AppInfoList.cpp index dadf508c04..6bb17f3288 100644 --- a/src/servers/registrar/AppInfoList.cpp +++ b/src/servers/registrar/AppInfoList.cpp @@ -186,15 +186,16 @@ AppInfoList::It() // Sort /*! \brief Sorts the infos in ascending order according to the given compare function. - \param cmpFunc The compare function to be used. + \param lessFunc The compare function (less than) to be used. */ void -AppInfoList::Sort(int (*cmpFunc)(const RosterAppInfo *, const RosterAppInfo *)) +AppInfoList::Sort( + bool (*lessFunc)(const RosterAppInfo *, const RosterAppInfo *)) { int32 count = CountInfos(); if (count > 1) { RosterAppInfo **infos = (RosterAppInfo **)fInfos.Items(); - std::sort(infos, infos + count, cmpFunc); + std::sort(infos, infos + count, lessFunc); } } diff --git a/src/servers/registrar/AppInfoList.h b/src/servers/registrar/AppInfoList.h index bf9c4ffb03..61fa5015f8 100644 --- a/src/servers/registrar/AppInfoList.h +++ b/src/servers/registrar/AppInfoList.h @@ -57,7 +57,7 @@ public: Iterator It(); - void Sort(int (*cmpFunc)(const RosterAppInfo *, const RosterAppInfo *)); + void Sort(bool (*lessFunc)(const RosterAppInfo *, const RosterAppInfo *)); private: RosterAppInfo *RemoveInfo(int32 index); diff --git a/src/servers/registrar/ShutdownProcess.cpp b/src/servers/registrar/ShutdownProcess.cpp index 645eb6664f..950acc7125 100644 --- a/src/servers/registrar/ShutdownProcess.cpp +++ b/src/servers/registrar/ShutdownProcess.cpp @@ -95,14 +95,11 @@ enum { // inverse_compare_by_registration_time static -int +bool inverse_compare_by_registration_time(const RosterAppInfo *info1, const RosterAppInfo *info2) { - bigtime_t cmp = info1->registration_time - info2->registration_time; - if (cmp < 0) - return 1; - return (cmp > 0 ? -1 : 0); + return (info2->registration_time < info1->registration_time); } // throw_error