aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Deri <deri@ntop.org>2021-02-19 15:15:02 +0100
committerLuca Deri <deri@ntop.org>2021-02-19 15:15:02 +0100
commit09559611ccf26d2817ad13425d3758a71faca4c8 (patch)
tree8cd79e5191eeeacb31d8456265a944b25840d29c
parentdee24f7acf949a66915144e5ccd7f6e578b28065 (diff)
Fixes #1136
-rw-r--r--src/lib/ndpi_analyze.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/lib/ndpi_analyze.c b/src/lib/ndpi_analyze.c
index 77400afd3..e142f914c 100644
--- a/src/lib/ndpi_analyze.c
+++ b/src/lib/ndpi_analyze.c
@@ -140,7 +140,8 @@ u_int32_t ndpi_data_max(struct ndpi_analyze_struct *s) { return(s->max_val); }
/* Compute the variance on all values */
float ndpi_data_variance(struct ndpi_analyze_struct *s) {
- return(s->num_data_entries ? ((float)s->stddev.sum_square_total - ((float)s->sum_total * (float)s->sum_total / (float)s->num_data_entries)) / (float)s->num_data_entries : 0.0);
+ float v = s->num_data_entries ? ((float)s->stddev.sum_square_total - ((float)s->sum_total * (float)s->sum_total / (float)s->num_data_entries)) / (float)s->num_data_entries : 0.0;
+ return((v < 0 /* rounding problem */) ? 0 : v);
}
/* ********************************************************************************* */