From 48b55382692b0d52dcb5d3f0c0bec6adcf06058e Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Wed, 16 Feb 2022 11:34:12 +0100 Subject: [PATCH] Fix defects detected by Coverity Scan 2021.12.1: Unintentional integer overflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit overflow_before_widen: Potentially overflowing expression this->d_fft_size * ninput_items[0UL] with type unsigned int (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type uint64_t (64 bits, unsigned) --- .../gnuradio_blocks/galileo_pcps_8ms_acquisition_cc.cc | 6 +++--- .../gnuradio_blocks/pcps_cccwsr_acquisition_cc.cc | 6 +++--- .../gnuradio_blocks/pcps_opencl_acquisition_cc.cc | 8 ++++---- .../gnuradio_blocks/pcps_quicksync_acquisition_cc.cc | 2 +- .../gnuradio_blocks/pcps_tong_acquisition_cc.cc | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/algorithms/acquisition/gnuradio_blocks/galileo_pcps_8ms_acquisition_cc.cc b/src/algorithms/acquisition/gnuradio_blocks/galileo_pcps_8ms_acquisition_cc.cc index 85ad12ff1..b534f30f9 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/galileo_pcps_8ms_acquisition_cc.cc +++ b/src/algorithms/acquisition/gnuradio_blocks/galileo_pcps_8ms_acquisition_cc.cc @@ -216,7 +216,7 @@ int galileo_pcps_8ms_acquisition_cc::general_work(int noutput_items, d_state = 1; } - d_sample_counter += static_cast(d_fft_size * ninput_items[0]); // sample counter + d_sample_counter += static_cast(d_fft_size) * ninput_items[0]; // sample counter consume_each(ninput_items[0]); break; @@ -368,7 +368,7 @@ int galileo_pcps_8ms_acquisition_cc::general_work(int noutput_items, d_active = false; d_state = 0; - d_sample_counter += d_fft_size * ninput_items[0]; // sample counter + d_sample_counter += static_cast(d_fft_size) * ninput_items[0]; // sample counter consume_each(ninput_items[0]); acquisition_message = 1; @@ -403,7 +403,7 @@ int galileo_pcps_8ms_acquisition_cc::general_work(int noutput_items, d_active = false; d_state = 0; - d_sample_counter += static_cast(d_fft_size * ninput_items[0]); // sample counter + d_sample_counter += static_cast(d_fft_size) * ninput_items[0]; // sample counter consume_each(ninput_items[0]); acquisition_message = 2; diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_cccwsr_acquisition_cc.cc b/src/algorithms/acquisition/gnuradio_blocks/pcps_cccwsr_acquisition_cc.cc index 47db3495a..47905fab9 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_cccwsr_acquisition_cc.cc +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_cccwsr_acquisition_cc.cc @@ -226,7 +226,7 @@ int pcps_cccwsr_acquisition_cc::general_work(int noutput_items, d_state = 1; } - d_sample_counter += static_cast(d_fft_size * ninput_items[0]); // sample counter + d_sample_counter += static_cast(d_fft_size) * ninput_items[0]; // sample counter consume_each(ninput_items[0]); break; @@ -389,7 +389,7 @@ int pcps_cccwsr_acquisition_cc::general_work(int noutput_items, d_active = false; d_state = 0; - d_sample_counter += static_cast(d_fft_size * ninput_items[0]); // sample counter + d_sample_counter += static_cast(d_fft_size) * ninput_items[0]; // sample counter consume_each(ninput_items[0]); acquisition_message = 1; @@ -424,7 +424,7 @@ int pcps_cccwsr_acquisition_cc::general_work(int noutput_items, d_active = false; d_state = 0; - d_sample_counter += static_cast(d_fft_size * ninput_items[0]); // sample counter + d_sample_counter += static_cast(d_fft_size) * ninput_items[0]; // sample counter consume_each(ninput_items[0]); acquisition_message = 2; diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_opencl_acquisition_cc.cc b/src/algorithms/acquisition/gnuradio_blocks/pcps_opencl_acquisition_cc.cc index 8aacb315f..b55015d6a 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_opencl_acquisition_cc.cc +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_opencl_acquisition_cc.cc @@ -680,7 +680,7 @@ int pcps_opencl_acquisition_cc::general_work(int noutput_items, d_state = 1; } - d_sample_counter += static_cast(d_fft_size * ninput_items[0]); // sample counter + d_sample_counter += static_cast(d_fft_size) * ninput_items[0]; // sample counter break; } @@ -710,7 +710,7 @@ int pcps_opencl_acquisition_cc::general_work(int noutput_items, { // We already have d_max_dwells consecutive blocks in the internal buffer, // just skip input blocks. - d_sample_counter += static_cast(d_fft_size * ninput_items[0]); + d_sample_counter += static_cast(d_fft_size) * ninput_items[0]; } // We create a new thread to process next block if the following @@ -754,7 +754,7 @@ int pcps_opencl_acquisition_cc::general_work(int noutput_items, d_active = false; d_state = 0; - d_sample_counter += static_cast(d_fft_size * ninput_items[0]); // sample counter + d_sample_counter += static_cast(d_fft_size) * ninput_items[0]; // sample counter acquisition_message = 1; this->message_port_pub(pmt::mp("events"), pmt::from_long(acquisition_message)); @@ -788,7 +788,7 @@ int pcps_opencl_acquisition_cc::general_work(int noutput_items, d_active = false; d_state = 0; - d_sample_counter += static_cast(d_fft_size * ninput_items[0]); // sample counter + d_sample_counter += static_cast(d_fft_size) * ninput_items[0]; // sample counter acquisition_message = 2; this->message_port_pub(pmt::mp("events"), pmt::from_long(acquisition_message)); diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_quicksync_acquisition_cc.cc b/src/algorithms/acquisition/gnuradio_blocks/pcps_quicksync_acquisition_cc.cc index 0463ef99f..3cf56f87a 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_quicksync_acquisition_cc.cc +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_quicksync_acquisition_cc.cc @@ -290,7 +290,7 @@ int pcps_quicksync_acquisition_cc::general_work(int noutput_items, d_test_statistics = 0.0; d_noise_floor_power = 0.0; - d_sample_counter += static_cast(d_sampled_ms * d_samples_per_ms); // sample counter + d_sample_counter += static_cast(d_sampled_ms) * d_samples_per_ms; // sample counter d_well_count++; diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_tong_acquisition_cc.cc b/src/algorithms/acquisition/gnuradio_blocks/pcps_tong_acquisition_cc.cc index b3c5c61a9..720bdf917 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_tong_acquisition_cc.cc +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_tong_acquisition_cc.cc @@ -251,7 +251,7 @@ int pcps_tong_acquisition_cc::general_work(int noutput_items, d_state = 1; } - d_sample_counter += static_cast(d_fft_size * ninput_items[0]); // sample counter + d_sample_counter += static_cast(d_fft_size) * ninput_items[0]; // sample counter consume_each(ninput_items[0]); break; @@ -390,7 +390,7 @@ int pcps_tong_acquisition_cc::general_work(int noutput_items, d_active = false; d_state = 0; - d_sample_counter += static_cast(d_fft_size * ninput_items[0]); // sample counter + d_sample_counter += static_cast(d_fft_size) * ninput_items[0]; // sample counter consume_each(ninput_items[0]); acquisition_message = 1; @@ -425,7 +425,7 @@ int pcps_tong_acquisition_cc::general_work(int noutput_items, d_active = false; d_state = 0; - d_sample_counter += static_cast(d_fft_size * ninput_items[0]); // sample counter + d_sample_counter += static_cast(d_fft_size) * ninput_items[0]; // sample counter consume_each(ninput_items[0]); acquisition_message = 2;