aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Nardi <12729895+IvanNardi@users.noreply.github.com>2024-09-03 12:41:50 +0200
committerGitHub <noreply@github.com>2024-09-03 12:41:50 +0200
commitf2da1698953cca5797003935bb90d69d4fbc3dda (patch)
treee4168f8ac42df176125b54dbd77d789647d50ed4 /src
parent767f403e0df2d86590ad2d898d90727b901e9b60 (diff)
bins: fix `ndpi_set_bin`, `ndpi_inc_bin` and `ndpi_get_bin_value` (#2536)
When the required slot is too big, use the latest/bigger available bin, not in the first one.
Diffstat (limited to 'src')
-rw-r--r--src/lib/ndpi_analyze.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lib/ndpi_analyze.c b/src/lib/ndpi_analyze.c
index 2df8118f0..519058a54 100644
--- a/src/lib/ndpi_analyze.c
+++ b/src/lib/ndpi_analyze.c
@@ -451,7 +451,7 @@ void ndpi_set_bin(struct ndpi_bin *b, u_int16_t slot_id, u_int64_t val) {
if(!b || !b->u.bins8 || b->num_bins == 0)
return;
- if(slot_id >= b->num_bins) slot_id = 0;
+ if(slot_id >= b->num_bins) slot_id = b->num_bins - 1;
switch(b->family) {
case ndpi_bin_family8:
@@ -477,7 +477,7 @@ void ndpi_inc_bin(struct ndpi_bin *b, u_int16_t slot_id, u_int64_t val) {
b->is_empty = 0;
- if(slot_id >= b->num_bins) slot_id = 0;
+ if(slot_id >= b->num_bins) slot_id = b->num_bins - 1;
switch(b->family) {
case ndpi_bin_family8:
@@ -501,7 +501,7 @@ u_int64_t ndpi_get_bin_value(struct ndpi_bin *b, u_int16_t slot_id) {
if(!b || !b->u.bins8 || b->num_bins == 0)
return(0);
- if(slot_id >= b->num_bins) slot_id = 0;
+ if(slot_id >= b->num_bins) slot_id = b->num_bins - 1;
switch(b->family) {
case ndpi_bin_family8: