Fixes bitmap memory calculation
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
E * ndpi_typedefs.h
|
* ndpi_typedefs.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011-23 - ntop.org
|
* Copyright (C) 2011-23 - ntop.org
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -47,10 +47,6 @@ ndpi_binary_bitmap* ndpi_binary_bitmap_alloc() {
|
|||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_BITMAP64_BINARY_BITMAP_MEMORY
|
|
||||||
rc->bitmap = NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rc->is_compressed = false;
|
rc->is_compressed = false;
|
||||||
|
|
||||||
return(rc);
|
return(rc);
|
||||||
@@ -138,21 +134,6 @@ bool ndpi_binary_bitmap_compress(ndpi_binary_bitmap *b) {
|
|||||||
|
|
||||||
b->is_compressed = true;
|
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);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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->is_compressed) ndpi_binary_bitmap_compress(b);
|
||||||
|
|
||||||
if(b->num_used_entries > 0) {
|
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 *rc;
|
||||||
struct ndpi_binary_bitmap_entry tofind;
|
struct ndpi_binary_bitmap_entry tofind;
|
||||||
|
|
||||||
@@ -177,7 +155,6 @@ bool ndpi_binary_bitmap_isset(ndpi_binary_bitmap *b, u_int64_t value, u_int8_t *
|
|||||||
*out_category = rc->category;
|
*out_category = rc->category;
|
||||||
|
|
||||||
return(rc == NULL ? false : true);
|
return(rc == NULL ? false : true);
|
||||||
#endif
|
|
||||||
} else
|
} else
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
@@ -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) {
|
void ndpi_binary_bitmap_free(ndpi_binary_bitmap *b) {
|
||||||
ndpi_free(b->entries);
|
ndpi_free(b->entries);
|
||||||
|
|
||||||
#ifdef USE_BITMAP64_BINARY_BITMAP_MEMORY
|
|
||||||
if(b->bitmap != NULL) ndpi_bitmap64_free(b->bitmap);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ndpi_free(b);
|
ndpi_free(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ********************************************************** */
|
/* ********************************************************** */
|
||||||
|
|
||||||
u_int32_t ndpi_binary_bitmap_size(ndpi_binary_bitmap *b) {
|
u_int32_t ndpi_binary_bitmap_size(ndpi_binary_bitmap *b) {
|
||||||
#ifdef USE_BITMAP64_BINARY_BITMAP_MEMORY
|
if(!b->is_compressed) ndpi_binary_bitmap_compress(b);
|
||||||
return(sizeof(ndpi_binary_bitmap) + ndpi_bitmap64_size(b->bitmap));
|
|
||||||
#else
|
|
||||||
return(sizeof(ndpi_binary_bitmap) + b->num_used_entries * sizeof(struct ndpi_binary_bitmap_entry));
|
return(sizeof(ndpi_binary_bitmap) + b->num_used_entries * sizeof(struct ndpi_binary_bitmap_entry));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ********************************************************** */
|
/* ********************************************************** */
|
||||||
|
|||||||
@@ -174,8 +174,6 @@ bool ndpi_bitmap64_isset(ndpi_bitmap64 *_b, u_int64_t value) {
|
|||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
if(!b->is_compressed) ndpi_bitmap64_compress(b);
|
if(!b->is_compressed) ndpi_bitmap64_compress(b);
|
||||||
if(!b->is_compressed)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
return(binary_fuse16_contain(value, &b->bitmap));
|
return(binary_fuse16_contain(value, &b->bitmap));
|
||||||
}
|
}
|
||||||
@@ -201,8 +199,8 @@ void ndpi_bitmap64_free(ndpi_bitmap64 *_b) {
|
|||||||
u_int32_t ndpi_bitmap64_size(ndpi_bitmap64 *_b) {
|
u_int32_t ndpi_bitmap64_size(ndpi_bitmap64 *_b) {
|
||||||
ndpi_bitmap64_t *b = (ndpi_bitmap64_t*)_b;
|
ndpi_bitmap64_t *b = (ndpi_bitmap64_t*)_b;
|
||||||
|
|
||||||
if(!b)
|
if(!b) return(0);
|
||||||
return(0);
|
if(!b->is_compressed) ndpi_bitmap64_compress(b);
|
||||||
|
|
||||||
return(sizeof(ndpi_bitmap64) + binary_fuse16_size_in_bytes(&b->bitmap));
|
return(sizeof(ndpi_bitmap64) + binary_fuse16_size_in_bytes(&b->bitmap));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user