comments.
* libmisc/cleanup.c: Fix off by one in an assertion.
+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.
}
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];
/* 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;