diff --git a/ChangeLog b/ChangeLog index 19c0189e..84fea96c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-09-08 Nicolas François + + * 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 * src/su.c: Fix indentation. diff --git a/lib/commonio.c b/lib/commonio.c index 6bad6622..3850da12 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -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]; diff --git a/libmisc/cleanup.c b/libmisc/cleanup.c index 732934c4..60f38e98 100644 --- a/libmisc/cleanup.c +++ b/libmisc/cleanup.c @@ -109,7 +109,8 @@ void del_cleanup (cleanup_function pcf) /* Move the rest of the cleanup functions */ for (; i