From: Lucas De Marchi Date: Tue, 27 Dec 2011 04:46:12 +0000 (-0200) Subject: Fix kmod_list_remove_n_latest() X-Git-Tag: v3~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb4ae531f7693c52fc42a612b99127e591575eed;p=thirdparty%2Fkmod.git Fix kmod_list_remove_n_latest() It only worked because n was always 1. kmod_list_remove returns a pointer to the next element, relative to the removed one. Therefore we need to always get a pointer to the last. --- diff --git a/libkmod/libkmod-list.c b/libkmod/libkmod-list.c index 4b68b77e..cf6df37e 100644 --- a/libkmod/libkmod-list.c +++ b/libkmod/libkmod-list.c @@ -241,26 +241,17 @@ struct kmod_list *kmod_list_remove_data(struct kmod_list *list, struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list, unsigned int n) { - struct kmod_list *l; + struct kmod_list *l = list; unsigned int i; - /* - * Get last element, remove all appended elments and if list became - * empty, set return pointer to NULL - */ - l = kmod_list_prev(list, list); - if (l == NULL) - l = list; - - for (i = 0; i < n; i++) + for (i = 0; i < n; i++) { + l = kmod_list_last(l); l = kmod_list_remove(l); + } - /* If list became empty, save it*/ - if (l == NULL) - list = NULL; - - return list; + return l; } + /** * kmod_list_prev: * @list: the head of the list