vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, Yesterday I committed a change to the queue.h macros to be able to find some specific bugs in the usage of these macros. pedro@ found out the hard way that removing the same element from the list twice can produce very funny results, as demonstrated by the program below, based on his example (the example output is created with the old queue.h). Here elements that were removed earlier suddenly reappear. The change I made causes a kernel panic or a core dump when the actual wrong operation takes place, rather than producing a bogus list that results in problems that are very hard to debug. This may uncover bugs in existing software. So please be aware of this change when trying to debug programs on -currennt. -Otto #include <sys/queue.h> #include <stdlib.h> #include <stdio.h> LIST_HEAD(head, element) list; struct element { char val; LIST_ENTRY(element) entries; }; int main(void) { struct element *a, *b, *c, *d, *z; LIST_INIT(&list); a = malloc(sizeof(struct element)); a->val = 'A'; LIST_INSERT_HEAD(&list, a, entries); b = malloc(sizeof(struct element)); b->val = 'B'; LIST_INSERT_HEAD(&list, b, entries); c = malloc(sizeof(struct element)); c->val = 'C'; LIST_INSERT_HEAD(&list, c, entries); d = malloc(sizeof(struct element)); d->val = 'D'; LIST_INSERT_HEAD(&list, d, entries); LIST_FOREACH(z, &list, entries) printf("%c\n", z->val); LIST_REMOVE(d, entries); LIST_REMOVE(c, entries); LIST_REMOVE(b, entries); LIST_REMOVE(a, entries); printf("== should be empty\n"); LIST_FOREACH(z, &list, entries) printf("%c\n", z->val); LIST_REMOVE(d, entries); printf("== after second remove of d\n"); LIST_FOREACH(z, &list, entries) printf("%c\n", z->val); } [otto@fonzo:57]$ ./a.out D C B A == should be empty == after second remove of d C B A [otto@fonzo:58]$ |