]> granicus.if.org Git - shadow/commitdiff
* lib/commonio.c: Avoid pre-decrement operator (--n). Add some
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Tue, 8 Sep 2009 21:00:12 +0000 (21:00 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Tue, 8 Sep 2009 21:00:12 +0000 (21:00 +0000)
comments.
* libmisc/cleanup.c: Fix off by one in an assertion.

ChangeLog
lib/commonio.c
libmisc/cleanup.c

index 19c0189e544d9e270aa18ba9f519e9e4ec9a4553..84fea96c22467e6cca13a941344039f0d2567941 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-09-08  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * lib/commonio.c: Avoid pre-decrement operator (--n). Add some
+       comments.
+       * libmisc/cleanup.c: Fix off by one in an assertion.
+
 2009-09-08  Nicolas François  <nicolas.francois@centraliens.net>
 
        * src/su.c: Fix indentation.
index 6bad6622a6c4491b9a2a47890ebc94850c1ad6b2..3850da121c0c4be7b58573819ebd3a848ea5d13f 100644 (file)
@@ -703,13 +703,16 @@ commonio_sort (struct commonio_db *db, int (*cmp) (const void *, const void *))
        }
        qsort (entries, n, sizeof (struct commonio_entry *), cmp);
 
+       /* Take care of the head and tail separately */
        db->head = entries[0];
-       db->tail = entries[--n];
+       n--;
+       db->tail = entries[n];
        db->head->prev = NULL;
        db->head->next = entries[1];
        db->tail->prev = entries[n - 1];
        db->tail->next = NULL;
 
+       /* Now other elements have prev and next entries */
        for (i = 1; i < n; i++) {
                entries[i]->prev = entries[i - 1];
                entries[i]->next = entries[i + 1];
index 732934c4225ece6ccaa27fbde733a932ed9c7790..60f38e98d78c8cbc17730ab2807d396da58805bd 100644 (file)
@@ -109,7 +109,8 @@ void del_cleanup (cleanup_function pcf)
        /* Move the rest of the cleanup functions */
        for (; i<CLEANUP_FUNCTIONS; i++) {
                /* Make sure the cleanup function was specified only once */
-               assert (cleanup_functions[i+1] != pcf);
+               assert (   (i == (CLEANUP_FUNCTIONS -1))
+                       || (cleanup_functions[i+1] != pcf));
 
                if (i == (CLEANUP_FUNCTIONS -1)) {
                        cleanup_functions[i] = NULL;