aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorheadshog <124502670+headshog@users.noreply.github.com>2023-05-30 13:27:47 +0300
committerGitHub <noreply@github.com>2023-05-30 12:27:47 +0200
commita8d2eeddd207d5bf70575045d632e235dcab2533 (patch)
treee12cb1874c45724e66218bfeaf327095c035ef18 /src
parent04f5c5196e790db8b8cc39e42c8645fb7f3dd141 (diff)
Numeric truncation at `ndpi_analyze.c` at lines 101, 104, 107, 110 (#1999)
* fixed numeric truncation error in ndpi_analyze.c * fixed numeric truncation error in ndpi_analyze.c x2 * fixed numeric truncation error in ndpi_analyze.c x3 * fixed numeric truncation error in ndpi_analyze.c and printf format * fixed tests
Diffstat (limited to 'src')
-rw-r--r--src/include/ndpi_api.h2
-rw-r--r--src/include/ndpi_typedefs.h5
-rw-r--r--src/lib/ndpi_analyze.c13
3 files changed, 11 insertions, 9 deletions
diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h
index eac4bcd25..c7912ef1d 100644
--- a/src/include/ndpi_api.h
+++ b/src/include/ndpi_api.h
@@ -1711,7 +1711,7 @@ extern "C" {
float ndpi_data_variance(struct ndpi_analyze_struct *s);
float ndpi_data_stddev(struct ndpi_analyze_struct *s);
float ndpi_data_mean(struct ndpi_analyze_struct *s);
- u_int32_t ndpi_data_last(struct ndpi_analyze_struct *s);
+ u_int64_t ndpi_data_last(struct ndpi_analyze_struct *s);
u_int32_t ndpi_data_min(struct ndpi_analyze_struct *s);
u_int32_t ndpi_data_max(struct ndpi_analyze_struct *s);
float ndpi_data_ratio(u_int32_t sent, u_int32_t rcvd);
diff --git a/src/include/ndpi_typedefs.h b/src/include/ndpi_typedefs.h
index 1cc55047c..b4392e1f3 100644
--- a/src/include/ndpi_typedefs.h
+++ b/src/include/ndpi_typedefs.h
@@ -1803,8 +1803,9 @@ typedef struct {
/* **************************************** */
struct ndpi_analyze_struct {
- u_int32_t *values;
- u_int32_t min_val, max_val, sum_total, num_data_entries, next_value_insert_index;
+ u_int64_t *values;
+ u_int64_t min_val, max_val, sum_total;
+ u_int32_t num_data_entries, next_value_insert_index;
u_int16_t num_values_array_len /* length of the values array */;
struct {
diff --git a/src/lib/ndpi_analyze.c b/src/lib/ndpi_analyze.c
index 75b650db5..d9828ad62 100644
--- a/src/lib/ndpi_analyze.c
+++ b/src/lib/ndpi_analyze.c
@@ -25,6 +25,7 @@
#include <errno.h>
#include <sys/types.h>
#include <stdint.h>
+#include <inttypes.h>
#include <math.h>
#include <float.h> /* FLT_EPSILON */
#include "ndpi_api.h"
@@ -41,7 +42,7 @@ void ndpi_init_data_analysis(struct ndpi_analyze_struct *ret, u_int16_t _max_ser
ret->num_values_array_len = _max_series_len;
if(ret->num_values_array_len > 0) {
- len = sizeof(u_int32_t) * ret->num_values_array_len;
+ len = sizeof(u_int64_t) * ret->num_values_array_len;
if((ret->values = ndpi_malloc(len)) != NULL)
memset(ret->values, 0, len);
else
@@ -70,7 +71,7 @@ void ndpi_free_data_analysis(struct ndpi_analyze_struct *d, u_int8_t free_pointe
/* ********************************************************************************* */
void ndpi_reset_data_analysis(struct ndpi_analyze_struct *d) {
- u_int32_t *values_bkp;
+ u_int64_t *values_bkp;
u_int32_t num_values_array_len_bpk;
if(!d)
@@ -85,7 +86,7 @@ void ndpi_reset_data_analysis(struct ndpi_analyze_struct *d) {
d->num_values_array_len = num_values_array_len_bpk;
if(d->values)
- memset(d->values, 0, sizeof(u_int32_t)*d->num_values_array_len);
+ memset(d->values, 0, sizeof(u_int64_t)*d->num_values_array_len);
}
/* ********************************************************************************* */
@@ -135,7 +136,7 @@ float ndpi_data_average(struct ndpi_analyze_struct *s) {
/* ********************************************************************************* */
-u_int32_t ndpi_data_last(struct ndpi_analyze_struct *s) {
+u_int64_t ndpi_data_last(struct ndpi_analyze_struct *s) {
if((!s) || (s->num_data_entries == 0) || (s->num_values_array_len == 0))
return(0);
@@ -264,8 +265,8 @@ void ndpi_data_print_window_values(struct ndpi_analyze_struct *s) {
u_int16_t i, n = ndpi_min(s->num_data_entries, s->num_values_array_len);
for(i=0; i<n; i++)
- printf("[%u: %u]", i, s->values[i]);
-
+ printf("[%u: %" PRIu64 "]", i, s->values[i]);
+
printf("\n");
}
}