Bug 1141431 - replace NS_QuickSort with qsort() at some call sites. r=mkmelin
authoraceman <acelists@atlas.sk>
Sun, 07 Oct 2018 14:50:00 +0200
changeset 33348 79048c9f59b451f786f7c9d50cca186f19b99d60
parent 33347 6cbc6a0b807bc16e084710dd5f94b26420bcdc62
child 33349 93e1d2a5aa87eaa625f0c7354076ccf13f20177e
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersmkmelin
bugs1141431
Bug 1141431 - replace NS_QuickSort with qsort() at some call sites. r=mkmelin
db/mork/src/morkQuickSort.cpp
mailnews/base/src/nsMessenger.cpp
mailnews/base/src/nsMsgTagService.cpp
--- a/db/mork/src/morkQuickSort.cpp
+++ b/db/mork/src/morkQuickSort.cpp
@@ -24,20 +24,16 @@
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
 
-/* We need this because Solaris' version of qsort is broken and
- * causes array bounds reads.
- */
-
 #ifndef _MDB_
 #include "mdb.h"
 #endif
 
 #ifndef _MORK_
 #include "mork.h"
 #endif
 
--- a/mailnews/base/src/nsMessenger.cpp
+++ b/mailnews/base/src/nsMessenger.cpp
@@ -2417,17 +2417,17 @@ public:
   nsresult Init(uint32_t aCount,
                 const char **aContentTypeArray,
                 const char **aUrlArray,
                 const char **aDisplayNameArray,
                 const char **aMessageUriArray);
   nsresult PrepareForAttachmentDelete();
 
 private:
-  static int SortAttachmentsByPartId(const void * aLeft, const void * aRight, void *);
+  static int SortAttachmentsByPartId(const void * aLeft, const void * aRight);
 
 public:
   uint32_t        mCount;
   uint32_t        mCurIndex;
   msgAttachment*  mAttachmentArray;
 };
 
 nsAttachmentState::nsAttachmentState()
@@ -2480,17 +2480,17 @@ nsAttachmentState::PrepareForAttachmentD
   // removal of the parent.
   //
   // e.g. the attachment list processing (showing only part ids)
   // before: 1.11, 1.3, 1.2, 1.2.1.3, 1.4.1.2
   // sorted: 1.2, 1.2.1.3, 1.3, 1.4.1.2, 1.11
   // after:  1.2, 1.3, 1.4.1.2, 1.11
 
   // sort
-  NS_QuickSort(mAttachmentArray, mCount, sizeof(msgAttachment), SortAttachmentsByPartId, nullptr);
+  qsort(mAttachmentArray, mCount, sizeof(msgAttachment), SortAttachmentsByPartId);
 
   // remove duplicates and sub-items
   int nCompare;
   for(uint32_t u = 1; u < mCount;)
   {
     nCompare = ::CompareAttachmentPartId(mAttachmentArray[u-1].mUrl, mAttachmentArray[u].mUrl);
     if (nCompare == 0 || nCompare == -2) // [u-1] is the same as or a parent of [u]
     {
@@ -2507,17 +2507,17 @@ nsAttachmentState::PrepareForAttachmentD
       ++u;
     }
   }
 
   return NS_OK;
 }
 
 int
-nsAttachmentState::SortAttachmentsByPartId(const void * aLeft, const void * aRight, void *)
+nsAttachmentState::SortAttachmentsByPartId(const void * aLeft, const void * aRight)
 {
   msgAttachment & attachLeft  = *((msgAttachment*) aLeft);
   msgAttachment & attachRight = *((msgAttachment*) aRight);
   return ::CompareAttachmentPartId(attachLeft.mUrl, attachRight.mUrl);
 }
 
 // ------------------------------------
 
--- a/mailnews/base/src/nsMsgTagService.cpp
+++ b/mailnews/base/src/nsMsgTagService.cpp
@@ -26,24 +26,24 @@
 #define TAG_CMP_LESSER          -1
 #define TAG_CMP_EQUAL           0
 #define TAG_CMP_GREATER         1
 
 static bool gMigratingKeys = false;
 
 // comparison functions for nsQuickSort
 static int
-CompareMsgTagKeys(const void* aTagPref1, const void* aTagPref2, void* aData)
+CompareMsgTagKeys(const void* aTagPref1, const void* aTagPref2)
 {
   return strcmp(*static_cast<const char* const*>(aTagPref1),
                 *static_cast<const char* const*>(aTagPref2));
 }
 
 static int
-CompareMsgTags(const void* aTagPref1, const void* aTagPref2, void* aData)
+CompareMsgTags(const void* aTagPref1, const void* aTagPref2)
 {
   // Sort nsMsgTag objects by ascending order, using their ordinal or key.
   // The "smallest" value will be first in the sorted array,
   // thus being the most important element.
   nsMsgTag *element1 = *(nsMsgTag**) aTagPref1;
   nsMsgTag *element2 = *(nsMsgTag**) aTagPref2;
 
   // if we have only one element, it wins
@@ -349,17 +349,17 @@ NS_IMETHODIMP nsMsgTagService::GetAllTag
 
   // get the actual tag definitions
   nsresult rv;
   uint32_t prefCount;
   char **prefList;
   rv = m_tagPrefBranch->GetChildList("", &prefCount, &prefList);
   NS_ENSURE_SUCCESS(rv, rv);
   // sort them by key for ease of processing
-  NS_QuickSort(prefList, prefCount, sizeof(char*), CompareMsgTagKeys, nullptr);
+  qsort(prefList, prefCount, sizeof(char*), CompareMsgTagKeys);
 
   // build an array of nsIMsgTag elements from the orderered list
   // it's at max the same size as the preflist, but usually only about half
   nsIMsgTag** tagArray = (nsIMsgTag**) moz_xmalloc(sizeof(nsIMsgTag*) * prefCount);
 
   if (!tagArray)
   {
     NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(prefCount, prefList);
@@ -404,18 +404,17 @@ NS_IMETHODIMP nsMsgTagService::GetAllTag
         }
         lastKey = key;
       }
     }
   }
   NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(prefCount, prefList);
 
   // sort the non-null entries by ordinal
-  NS_QuickSort(tagArray, currentTagIndex, sizeof(nsMsgTag*), CompareMsgTags,
-               nullptr);
+  qsort(tagArray, currentTagIndex, sizeof(nsMsgTag*), CompareMsgTags);
 
   // All done, now return the values (the idl's size_is(count) parameter
   // ensures that the array is cut accordingly).
   *aCount = currentTagIndex;
   *aTagArray = tagArray;
 
   return NS_OK;
 }