diff --git a/libclamav/bytecode_api.c b/libclamav/bytecode_api.c index afaea1f99..3f1a0b2e0 100644 --- a/libclamav/bytecode_api.c +++ b/libclamav/bytecode_api.c @@ -504,8 +504,7 @@ int32_t cli_bcapi_hashset_remove(struct cli_bc_ctx *ctx , int32_t id, uint32_t k struct cli_hashset *s = get_hashset(ctx, id); if (!s) return -1; -// return cli_hashset_removekey(s, key); - return -1; + return cli_hashset_removekey(s, key); } int32_t cli_bcapi_hashset_contains(struct cli_bc_ctx *ctx , int32_t id, uint32_t key) diff --git a/libclamav/hashtab.c b/libclamav/hashtab.c index d8f19be53..fc99a81f5 100644 --- a/libclamav/hashtab.c +++ b/libclamav/hashtab.c @@ -453,6 +453,7 @@ void cli_hashset_destroy(struct cli_hashset* hs) #define BITMAP_CONTAINS(bmap, val) ((bmap)[(val) >> 5] & (1 << ((val) & 0x1f))) #define BITMAP_INSERT(bmap, val) ((bmap)[(val) >> 5] |= (1 << ((val) & 0x1f))) +#define BITMAP_REMOVE(bmap, val) ((bmap)[(val) >> 5] &= ~(1 << ((val) & 0x1f))) /* * searches the hashset for the @key. @@ -475,7 +476,6 @@ static inline size_t cli_hashset_search(const struct cli_hashset* hs, const uint return idx; } - static void cli_hashset_addkey_internal(struct cli_hashset* hs, const uint32_t key) { const size_t idx = cli_hashset_search(hs, key); @@ -529,6 +529,16 @@ int cli_hashset_addkey(struct cli_hashset* hs, const uint32_t key) return 0; } +int cli_hashset_removekey(struct cli_hashset* hs, const uint32_t key) +{ + const size_t idx = cli_hashset_search(hs, key); + if (BITMAP_CONTAINS(hs->bitmap, idx)) { + BITMAP_REMOVE(hs->bitmap, idx); + hs->keys[idx] = 0; + hs->count--; + } +} + int cli_hashset_contains(const struct cli_hashset* hs, const uint32_t key) { const size_t idx = cli_hashset_search(hs, key); diff --git a/libclamav/hashtab.h b/libclamav/hashtab.h index 33f079e3e..8ab6786bb 100644 --- a/libclamav/hashtab.h +++ b/libclamav/hashtab.h @@ -104,6 +104,7 @@ int cli_hashset_contains(const struct cli_hashset* hs, const uint32_t key); int cli_hashset_clear(struct cli_hashset* hs); void cli_hashset_destroy(struct cli_hashset* hs); ssize_t cli_hashset_toarray(const struct cli_hashset* hs, uint32_t** array); +int cli_hashset_removekey(struct cli_hashset* hs, const uint32_t key); /* Initializes the set without allocating memory, you can do lookups on it * using _contains_maybe_noalloc. You need to initialize it using _init