* lib/commonio.c: Avoid pre-decrement operator (--n). Add some

comments.
	* libmisc/cleanup.c: Fix off by one in an assertion.
This commit is contained in:
nekral-guest
2009-09-08 21:00:12 +00:00
parent a845c67c60
commit 1e51ab0b23
3 changed files with 12 additions and 2 deletions

View 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];