From 545d9eaeff62af74b6c1d2c27e6067f40685af93 Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Wed, 13 Dec 2017 11:43:13 -0500 Subject: VPP-1032: clean up coverity warnings. "This time, for sure..." Change-Id: Ie981003842d37c5eb6a0b2fe3abe974a93b86df8 Signed-off-by: Dave Barach --- src/vppinfra/maplog.c | 1 + src/vppinfra/random.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/vppinfra/maplog.c b/src/vppinfra/maplog.c index 158361b0bda..deb07aa9b76 100644 --- a/src/vppinfra/maplog.c +++ b/src/vppinfra/maplog.c @@ -394,6 +394,7 @@ clib_maplog_process (char *file_basename, void *fp_arg) goto out; } (void) close (fd); + fd = -1; file_size_in_bytes = h->file_size_in_records * h->record_size_in_cachelines * CLIB_CACHE_LINE_BYTES; diff --git a/src/vppinfra/random.c b/src/vppinfra/random.c index e54a3bc8c7c..ea89f0a1618 100644 --- a/src/vppinfra/random.c +++ b/src/vppinfra/random.c @@ -63,20 +63,26 @@ u32 standalone_random_default_seed = 1; f64 clib_chisquare (u64 * values) { - int i; + u32 i, len; f64 d, delta_d, actual_frequency, expected_frequency; u64 n_observations = 0; - ASSERT (vec_len (values)); + len = vec_len (values); + /* + * Shut up coverity. Return a huge number which should always exceed + * the X2 critical value. + */ + if (len == 0) + return (f64) 1e70; - for (i = 0; i < vec_len (values); i++) + for (i = 0; i < len; i++) n_observations += values[i]; - expected_frequency = (1.0 / (f64) vec_len (values)) * (f64) n_observations; + expected_frequency = (1.0 / (f64) len) * (f64) n_observations; d = 0.0; - for (i = 0; i < vec_len (values); i++) + for (i = 0; i < len; i++) { actual_frequency = ((f64) values[i]); delta_d = ((actual_frequency - expected_frequency) -- cgit 1.2.3-korg