From dd8be1fcb11089b22ab5eb7332d5640b4cae80b0 Mon Sep 17 00:00:00 2001 From: Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> Date: Fri, 12 Jan 2024 13:30:43 +0100 Subject: Fix some warnings reported by CODESonar (#2227) Remove some unreached/duplicated code. Add error checking for `atoi()` calls. About `isdigit()` and similar functions. The warning reported is: ``` Negative Character Value help isdigit() is invoked here with an argument of signed type char, but only has defined behavior for int arguments that are either representable as unsigned char or equal to the value of macro EOF(-1). Casting the argument to unsigned char will avoid the undefined behavior. In a number of libc implementations, isdigit() is implemented using lookup tables (arrays): passing in a negative value can result in a read underrun. ``` Switching to our macros fix that. Add a check to `check_symbols.sh` to avoid using the original functions from libc. --- src/lib/ndpi_analyze.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib/ndpi_analyze.c') diff --git a/src/lib/ndpi_analyze.c b/src/lib/ndpi_analyze.c index d1b1c38ec..bcfe60a18 100644 --- a/src/lib/ndpi_analyze.c +++ b/src/lib/ndpi_analyze.c @@ -148,7 +148,7 @@ float ndpi_data_average(struct ndpi_analyze_struct *s) { if((!s) || (s->num_data_entries == 0)) return(0); - return((s->num_data_entries == 0) ? 0 : ((float)s->sum_total / (float)s->num_data_entries)); + return((float)s->sum_total / (float)s->num_data_entries); } /* ********************************************************************************* */ -- cgit v1.2.3