X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/65bb0fff13f2099c2746d6b8c9ad2421e9419d07..6fc592ffe67215116e84a6c31a31ede189aa6c0e:/lib/selection.c diff --git a/lib/selection.c b/lib/selection.c index c69e83d..6d0a588 100644 --- a/lib/selection.c +++ b/lib/selection.c @@ -21,8 +21,7 @@ * @brief Select management for Disobedience */ -#include -#include "types.h" +#include "common.h" #include "mem.h" #include "hash.h" @@ -44,9 +43,11 @@ hash *selection_new(void) { * are not marked as live. */ void selection_set(hash *h, const char *key, int selected) { - if(selected) - hash_add(h, key, xmalloc_noptr(sizeof (int)), HASH_INSERT_OR_REPLACE); - else + if(selected) { + int *const liveness = xmalloc_noptr(sizeof (int)); + *liveness = 0; + hash_add(h, key, liveness, HASH_INSERT_OR_REPLACE); + } else hash_remove(h, key); } @@ -96,7 +97,7 @@ static int selection_cleanup_callback(const char *key, /** @brief Delete all non-live keys from a selection * @param h Hash representing selection * - * See selection_live(). + * After cleanup, no keys are marked as live. */ void selection_cleanup(hash *h) { hash_foreach(h, selection_cleanup_callback, h);