Skip to content

Commit

Permalink
Fixes bitmap memory calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaderi committed Mar 11, 2024
1 parent 6152d59 commit 1aedbef
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/include/ndpi_typedefs.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
E * ndpi_typedefs.h
* ndpi_typedefs.h
*
* Copyright (C) 2011-23 - ntop.org
*
Expand Down
33 changes: 2 additions & 31 deletions src/lib/ndpi_binary_bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ ndpi_binary_bitmap* ndpi_binary_bitmap_alloc() {
return(NULL);
}

#ifdef USE_BITMAP64_BINARY_BITMAP_MEMORY
rc->bitmap = NULL;
#endif

rc->is_compressed = false;

return(rc);
Expand Down Expand Up @@ -138,21 +134,6 @@ bool ndpi_binary_bitmap_compress(ndpi_binary_bitmap *b) {

b->is_compressed = true;

#ifdef USE_BITMAP64_BINARY_BITMAP_MEMORY
if(b->bitmap != NULL) ndpi_bitmap64_free(b->bitmap);
b->bitmap = ndpi_bitmap64_alloc_size(b->num_used_entries);

u_int64_t *values = (u_int64_t*)ndpi_malloc(sizeof(u_int64_t)*b->num_used_entries);

if(values) {
for(i=0; i<b->num_used_entries; i++)
values[i] = b->entries[i].value;

ndpi_bitmap64_multiset(b->bitmap, values, b->num_used_entries);
ndpi_free(values);
}
#endif

return(true);
}

Expand All @@ -162,9 +143,6 @@ bool ndpi_binary_bitmap_isset(ndpi_binary_bitmap *b, u_int64_t value, u_int8_t *
if(!b->is_compressed) ndpi_binary_bitmap_compress(b);

if(b->num_used_entries > 0) {
#ifdef USE_BITMAP64_BINARY_BITMAP_MEMORY
return(ndpi_bitmap64_isset(b->bitmap, value));
#else
struct ndpi_binary_bitmap_entry *rc;
struct ndpi_binary_bitmap_entry tofind;

Expand All @@ -177,7 +155,6 @@ bool ndpi_binary_bitmap_isset(ndpi_binary_bitmap *b, u_int64_t value, u_int8_t *
*out_category = rc->category;

return(rc == NULL ? false : true);
#endif
} else
return(false);
}
Expand All @@ -187,21 +164,15 @@ bool ndpi_binary_bitmap_isset(ndpi_binary_bitmap *b, u_int64_t value, u_int8_t *
void ndpi_binary_bitmap_free(ndpi_binary_bitmap *b) {
ndpi_free(b->entries);

#ifdef USE_BITMAP64_BINARY_BITMAP_MEMORY
if(b->bitmap != NULL) ndpi_bitmap64_free(b->bitmap);
#endif

ndpi_free(b);
}

/* ********************************************************** */

u_int32_t ndpi_binary_bitmap_size(ndpi_binary_bitmap *b) {
#ifdef USE_BITMAP64_BINARY_BITMAP_MEMORY
return(sizeof(ndpi_binary_bitmap) + ndpi_bitmap64_size(b->bitmap));
#else
if(!b->is_compressed) ndpi_binary_bitmap_compress(b);

return(sizeof(ndpi_binary_bitmap) + b->num_used_entries * sizeof(struct ndpi_binary_bitmap_entry));
#endif
}

/* ********************************************************** */
Expand Down
8 changes: 3 additions & 5 deletions src/lib/ndpi_bitmap64.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ bool ndpi_bitmap64_isset(ndpi_bitmap64 *_b, u_int64_t value) {
return(false);

if(!b->is_compressed) ndpi_bitmap64_compress(b);
if(!b->is_compressed)
return(false);

return(binary_fuse16_contain(value, &b->bitmap));
}
Expand All @@ -201,8 +199,8 @@ void ndpi_bitmap64_free(ndpi_bitmap64 *_b) {
u_int32_t ndpi_bitmap64_size(ndpi_bitmap64 *_b) {
ndpi_bitmap64_t *b = (ndpi_bitmap64_t*)_b;

if(!b)
return(0);

if(!b) return(0);
if(!b->is_compressed) ndpi_bitmap64_compress(b);
return(sizeof(ndpi_bitmap64) + binary_fuse16_size_in_bytes(&b->bitmap));
}

0 comments on commit 1aedbef

Please sign in to comment.