Message Deletion: only use one memmove to remove leading empty message numbers
authorWilfried Goesgens <dothebart@citadel.org>
Sat, 8 Jun 2013 15:02:49 +0000 (17:02 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Sat, 8 Jun 2013 15:02:49 +0000 (17:02 +0200)
citadel/room_ops.c

index c657378f89af5885ca82fcf0d9dc3d68125569af..010fa12766a3e617e9adbe6df7de2395e9d1bb20 100644 (file)
@@ -659,6 +659,7 @@ int sort_msglist_cmp(const void *m1, const void *m2) {
 int sort_msglist(long listptrs[], int oldcount)
 {
        int numitems;
+       int i = 0;
 
        numitems = oldcount;
        if (numitems < 2) {
@@ -669,9 +670,12 @@ int sort_msglist(long listptrs[], int oldcount)
        qsort(listptrs, numitems, sizeof(long), sort_msglist_cmp);
 
        /* and yank any nulls */
-       while ((numitems > 0) && (listptrs[0] == 0L)) {
-               memmove(&listptrs[0], &listptrs[1], (sizeof(long) * (numitems - 1)));
-               --numitems;
+       while ((i < numitems) && (listptrs[i] == 0L)) i++;
+
+       if (i > 0)
+       {
+               memmove(&listptrs[0], &listptrs[i], (sizeof(long) * (numitems - i)));
+               numitems-=i;
        }
 
        return (numitems);