Fix member initializations, potential data race conditions, and minor performance issues detected by Coverity Scan

Never throw from main
This commit is contained in:
Carles Fernandez 2023-12-21 13:57:41 +01:00
parent d8fabdb4ac
commit 4916c6c8e8
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
16 changed files with 438 additions and 357 deletions

View File

@ -5651,7 +5651,7 @@ void Rinex_Printer::log_rinex_nav(std::fstream& out, const std::map<int32_t, Gal
std::string E1B_DVS = std::to_string(galileo_ephemeris_iter->second.E1B_DVS);
std::string SVhealth_str = std::move(E5B_HS) + std::to_string(galileo_ephemeris_iter->second.E5b_DVS) + "11" + "1" + std::string(E1B_DVS) + std::string(E1B_HS) + std::to_string(galileo_ephemeris_iter->second.E1B_DVS);
std::string SVhealth_str = std::move(E5B_HS) + std::to_string(galileo_ephemeris_iter->second.E5b_DVS) + "11" + "1" + std::move(E1B_DVS) + std::move(E1B_HS) + std::to_string(galileo_ephemeris_iter->second.E1B_DVS);
int32_t SVhealth = Rinex_Printer::toInt(SVhealth_str, 9);
line += Rinex_Printer::doub2for(static_cast<double>(SVhealth), 18, 2);
line += std::string(1, ' ');

View File

@ -33,6 +33,7 @@
#include <cstdint> // for uint32_t
#include <memory> // for shared_ptr
#include <string> // for string
#include <utility> // for move
/** \addtogroup Acquisition
* \{ */
@ -118,7 +119,7 @@ public:
*/
inline void set_channel_fsm(std::weak_ptr<ChannelFsm> channel_fsm)
{
d_channel_fsm = channel_fsm;
d_channel_fsm = std::move(channel_fsm);
}
/*!

View File

@ -21,6 +21,7 @@
#include <glog/logging.h>
#include <cmath>
#include <iostream>
#include <utility>
void Acq_Conf_Fpga::SetFromConfiguration(const ConfigurationInterface *configuration,
const std::string &role, uint32_t sel_queue_fpga, uint32_t blk_exp, uint32_t downsampling_factor_default, double chip_rate, double code_length_chips)
@ -58,7 +59,7 @@ void Acq_Conf_Fpga::SetFromConfiguration(const ConfigurationInterface *configura
std::cout << "Cannot find the FPGA uio device file corresponding to device name " << acquisition_device_name << std::endl;
throw std::exception();
}
device_name = device_io_name;
device_name = std::move(device_io_name);
// exclusion limit
excludelimit = static_cast<unsigned int>(1 + ceil((1.0 / chip_rate) * static_cast<float>(fs_in)));

View File

@ -450,7 +450,7 @@ bool config_ad9361_rx_local(uint64_t bandwidth_,
{
return false;
}
if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq1_, rf_port_select_, ad9361_phy_B, rx_chan1, chn, 0, filter_filename_, Fpass_, Fstop_) == -1)
if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq1_, rf_port_select_, ad9361_phy_B, rx_chan1, chn, 0, std::move(filter_filename_), Fpass_, Fstop_) == -1)
{
return false;
}
@ -472,7 +472,7 @@ bool config_ad9361_rx_local(uint64_t bandwidth_,
std::cout << rx_stream_dev_a << " channel 1 not found\n";
throw std::runtime_error(rx_stream_dev_a + "RX channel 1 not found");
}
if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq0_, rf_port_select_, ad9361_phy, rx_chan1, chn, 1, filter_filename_, Fpass_, Fstop_) == -1)
if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq0_, rf_port_select_, ad9361_phy, rx_chan1, chn, 1, std::move(filter_filename_), Fpass_, Fstop_) == -1)
{
return false;
}

View File

@ -29,6 +29,12 @@
Fpga_dynamic_bit_selection::Fpga_dynamic_bit_selection(bool enable_rx1_band, bool enable_rx2_band)
: d_enable_rx1_band(enable_rx1_band), d_enable_rx2_band(enable_rx2_band)
{
d_map_base_freq_band_1 = nullptr;
d_map_base_freq_band_2 = nullptr;
d_dev_descr_freq_band_1 = 0;
d_dev_descr_freq_band_2 = 0;
d_shift_out_bits_freq_band_1 = 0;
d_shift_out_bits_freq_band_2 = 0;
if (d_enable_rx1_band)
{
open_device(&d_map_base_freq_band_1, d_dev_descr_freq_band_1, 0);
@ -41,7 +47,7 @@ Fpga_dynamic_bit_selection::Fpga_dynamic_bit_selection(bool enable_rx1_band, boo
{
open_device(&d_map_base_freq_band_2, d_dev_descr_freq_band_2, 1);
// init bit selection corresponding to frequency band 1
// init bit selection corresponding to frequency band 2
d_shift_out_bits_freq_band_2 = shift_out_bits_default;
d_map_base_freq_band_2[0] = d_shift_out_bits_freq_band_2;
}

View File

@ -446,7 +446,7 @@ dll_pll_veml_tracking_fpga::dll_pll_veml_tracking_fpga(const Dll_Pll_Conf_Fpga &
{
std::string dump_filename_ = d_dump_filename.substr(d_dump_filename.find_last_of('/') + 1);
dump_path = d_dump_filename.substr(0, d_dump_filename.find_last_of('/'));
d_dump_filename = dump_filename_;
d_dump_filename = std::move(dump_filename_);
}
else
{
@ -1383,6 +1383,7 @@ void dll_pll_veml_tracking_fpga::set_gnss_synchro(Gnss_Synchro *p_gnss_synchro)
d_acquisition_gnss_synchro = p_gnss_synchro;
if (p_gnss_synchro->PRN > 0)
{
gr::thread::scoped_lock lock(d_setlock);
// A set_gnss_synchro command with a valid PRN is received when the system is going to run acquisition with that PRN.
// We can use this command to pre-initialize tracking parameters and variables before the actual acquisition process takes place.
// In this way we minimize the latency between acquisition and tracking once the acquisition has been made.
@ -1527,8 +1528,8 @@ int dll_pll_veml_tracking_fpga::general_work(int noutput_items __attribute__((un
{
case 1: // Pull-in
{
d_worker_is_done = false;
boost::mutex::scoped_lock lock(d_mutex);
d_worker_is_done = false;
while (!d_worker_is_done)
{
d_m_condition.wait(lock);

View File

@ -308,10 +308,6 @@ void Gps_L1_Ca_Gaussian_Tracking_cc::start_tracking()
sys = std::string(1, d_acquisition_gnss_synchro->System);
// DEBUG OUTPUT
std::cout << "Tracking of GPS L1 C/A signal started on channel " << d_channel << " for satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN) << '\n';
LOG(INFO) << "Starting tracking of satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN) << " on channel " << d_channel;
// enable tracking
d_pull_in = true;
d_enable_tracking = true;
@ -319,6 +315,10 @@ void Gps_L1_Ca_Gaussian_Tracking_cc::start_tracking()
LOG(INFO) << "PULL-IN Doppler [Hz]=" << d_carrier_doppler_hz
<< " Code Phase correction [samples]=" << delay_correction_samples
<< " PULL-IN Code Phase [samples]=" << d_acq_code_phase_samples;
gr::thread::scoped_lock l(d_setlock);
std::cout << "Tracking of GPS L1 C/A signal started on channel " << d_channel << " for satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN) << '\n';
LOG(INFO) << "Starting tracking of satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN) << " on channel " << d_channel;
}
@ -776,6 +776,7 @@ int Gps_L1_Ca_Gaussian_Tracking_cc::general_work(int noutput_items __attribute__
}
if (d_carrier_lock_fail_counter > FLAGS_max_lock_fail)
{
gr::thread::scoped_lock l(d_setlock);
std::cout << "Loss of lock in channel " << d_channel << "!\n";
LOG(INFO) << "Loss of lock in channel " << d_channel << "!";
this->message_port_pub(pmt::mp("events"), pmt::from_long(3)); // 3 -> loss of lock

View File

@ -57,20 +57,26 @@ Fpga_Multicorrelator_8sc::Fpga_Multicorrelator_8sc(int32_t n_correlators,
d_Prompt_Data(nullptr),
d_shifts_chips(nullptr),
d_prompt_data_shift(nullptr),
d_rem_code_phase_chips(0),
d_code_phase_step_chips(0),
d_rem_carrier_phase_in_rad(0),
d_phase_step_rad(0),
d_rem_code_phase_chips(0.0),
d_code_phase_step_chips(0.0),
d_code_phase_rate_step_chips(0.0),
d_rem_carrier_phase_in_rad(0.0),
d_phase_step_rad(0.0),
d_carrier_phase_rate_step_rad(0.0),
d_code_length_samples(code_length_chips * code_samples_per_chip),
d_n_correlators(n_correlators),
d_device_descriptor(0),
d_map_base(nullptr),
d_correlator_length_samples(0),
d_code_phase_step_chips_num(0),
d_code_phase_rate_step_chips_num(0),
d_rem_carr_phase_rad_int(0),
d_phase_step_rad_int(0),
d_carrier_phase_rate_step_rad_int(0),
d_ca_codes(ca_codes),
d_data_codes(data_codes),
d_secondary_code_0_length(0),
d_secondary_code_1_length(0),
d_track_pilot(track_pilot),
d_secondary_code_enabled(false)
{

View File

@ -2097,6 +2097,7 @@ void GNSSFlowgraph::set_configuration(const std::shared_ptr<ConfigurationInterfa
#if ENABLE_FPGA
void GNSSFlowgraph::start_acquisition_helper()
{
std::lock_guard<std::mutex> lock(signal_list_mutex_);
for (int i = 0; i < channels_count_; i++)
{
if (channels_state_[i] == 1)

View File

@ -91,6 +91,7 @@ GalileoE1PcpsAmbiguousAcquisitionTestFpga::GalileoE1PcpsAmbiguousAcquisitionTest
doppler_max = 5000;
doppler_step = 100;
nsamples_to_transfer = 0;
}
@ -280,7 +281,7 @@ public:
}
private:
bool acquisition_successful;
bool acquisition_successful{};
};
@ -310,7 +311,7 @@ bool GalileoE1PcpsAmbiguousAcquisitionTestFpga::acquire_signal()
args.scaling_factor = DMA_SIGNAL_SCALING_FACTOR;
std::string file = "data/Galileo_E1_ID_1_Fs_4Msps_8ms.dat";
args.file = file; // DMA file configuration
args.file = std::move(file); // DMA file configuration
// instantiate the FPGA switch and set the
// switch position to DMA.
@ -348,7 +349,7 @@ bool GalileoE1PcpsAmbiguousAcquisitionTestFpga::acquire_signal()
args.nsamples_tx = nsamples_to_transfer;
// run the acquisition. The acquisition must run in a separate thread because it is a blocking function
args_acq.acquisition = acquisition;
args_acq.acquisition = std::move(acquisition);
if (pthread_create(&thread_acquisition, nullptr, handler_acquisition_galileo_e1_pcps_ambiguous_acq_test, reinterpret_cast<void*>(&args_acq)) < 0)
{

View File

@ -279,7 +279,7 @@ public:
}
private:
bool acquisition_successful;
bool acquisition_successful{};
};
@ -309,7 +309,7 @@ bool GpsL1CaPcpsAcquisitionTestFpga::acquire_signal()
args.scaling_factor = DMA_SIGNAL_SCALING_FACTOR;
std::string file = "data/GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat";
args.file = file; // DMA file configuration
args.file = std::move(file); // DMA file configuration
// instantiate the FPGA switch and set the
// switch position to DMA.
@ -347,7 +347,7 @@ bool GpsL1CaPcpsAcquisitionTestFpga::acquire_signal()
args.nsamples_tx = nsamples_to_transfer;
// run the acquisition. The acquisition must run in a separate thread because it is a blocking function
args_acq.acquisition = acquisition;
args_acq.acquisition = std::move(acquisition);
if (pthread_create(&thread_acquisition, nullptr, handler_acquisition_gps_l1_acq_test, reinterpret_cast<void*>(&args_acq)) < 0)
{

View File

@ -224,7 +224,7 @@ TEST_F(FirFilterTest, ConnectAndRunGrcomplex)
config2->set_property("Test_Source.sampling_frequency", "4000000");
std::string path = std::string(TEST_PATH);
std::string filename = path + "signal_samples/GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat";
config2->set_property("Test_Source.filename", filename);
config2->set_property("Test_Source.filename", std::move(filename));
config2->set_property("Test_Source.item_type", "gr_complex");
config2->set_property("Test_Source.repeat", "true");

View File

@ -21,6 +21,7 @@
#include <complex>
#include <cstdint>
#include <thread>
#include <utility>
#ifdef GR_GREATER_38
#include <gnuradio/analog/sig_source.h>
#else
@ -177,7 +178,7 @@ TEST_F(NotchFilterTest, ConnectAndRunGrcomplex)
config2->set_property("Test_Source.sampling_frequency", "4000000");
std::string path = std::string(TEST_PATH);
std::string filename = path + "signal_samples/GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat";
config2->set_property("Test_Source.filename", filename);
config2->set_property("Test_Source.filename", std::move(filename));
config2->set_property("Test_Source.item_type", "gr_complex");
config2->set_property("Test_Source.repeat", "true");

View File

@ -21,6 +21,7 @@
#include <complex>
#include <cstdint>
#include <thread>
#include <utility>
#ifdef GR_GREATER_38
#include <gnuradio/analog/sig_source.h>
#else
@ -176,7 +177,7 @@ TEST_F(PulseBlankingFilterTest, ConnectAndRunGrcomplex)
config2->set_property("Test_Source.sampling_frequency", "4000000");
std::string path = std::string(TEST_PATH);
std::string filename = path + "signal_samples/GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat";
config2->set_property("Test_Source.filename", filename);
config2->set_property("Test_Source.filename", std::move(filename));
config2->set_property("Test_Source.item_type", "gr_complex");
config2->set_property("Test_Source.repeat", "true");

View File

@ -269,6 +269,8 @@ static time_t utc_time(int week, int64_t tow)
int main(int argc, char** argv)
{
try
{
const std::string intro_help(
std::string("\n RTL-SDR E4000 RF front-end center frequency and sampling rate calibration tool that uses GPS signals\n") +
"Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)\n" +
@ -280,7 +282,13 @@ int main(int argc, char** argv)
gflags::ParseCommandLineFlags(&argc, &argv, true);
std::cout << "Initializing... Please wait.\n";
}
catch (const std::exception& e)
{
std::cerr << e.what() << '\n';
std::cout << "front-end-cal program ended.\n";
return 1;
}
google::InitGoogleLogging(argv[0]);
if (FLAGS_log_dir.empty())
{
@ -291,6 +299,8 @@ int main(int argc, char** argv)
<< '\n';
}
else
{
try
{
const fs::path p(FLAGS_log_dir);
if (!fs::exists(p))
@ -299,13 +309,29 @@ int main(int argc, char** argv)
<< FLAGS_log_dir
<< " does not exist, attempting to create it"
<< '\n';
fs::create_directory(p);
errorlib::error_code ec;
if (!fs::create_directory(p, ec))
{
std::cerr << "Could not create the " << FLAGS_log_dir << " folder. Front-end-cal program ended.\n";
gflags::ShutDownCommandLineFlags();
return 1;
}
}
std::cout << "Logging with be done at "
<< FLAGS_log_dir << '\n';
}
catch (const std::exception& e)
{
std::cerr << e.what() << '\n';
std::cerr << "Could not create the " << FLAGS_log_dir << " folder. Front-end-cal program ended.\n";
gflags::ShutDownCommandLineFlags();
return 1;
}
}
// 0. Instantiate the FrontEnd Calibration class
try
{
FrontEndCal front_end_cal;
// 1. Load configuration parameters from config file
@ -643,7 +669,21 @@ int main(int argc, char** argv)
std::cout << " " << it.first << " " << it.second - mean_f_if_Hz << " (Eph not found)\n";
}
}
}
catch (const std::exception& e)
{
std::cerr << "Exception: " << e.what();
gflags::ShutDownCommandLineFlags();
return 1;
}
catch (...)
{
std::cerr << "Unknown error\n";
gflags::ShutDownCommandLineFlags();
return 1;
}
gflags::ShutDownCommandLineFlags();
std::cout << "GNSS-SDR Front-end calibration program ended.\n";
return 0;
}

View File

@ -30,6 +30,7 @@
#include <set>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
#if GNSSTK_USES_GPSTK_NAMESPACE
@ -673,7 +674,7 @@ void carrier_doppler_single_diff(
{
// 2. RMSE
arma::vec err;
err = delta_measured_carrier_doppler_cycles;
err = std::move(delta_measured_carrier_doppler_cycles);
arma::vec err2 = arma::square(err);
double rmse = sqrt(arma::mean(err2));
@ -865,7 +866,7 @@ void code_pseudorange_single_diff(
// 2. RMSE
arma::vec err;
err = delta_measured_obs;
err = std::move(delta_measured_obs);
arma::vec err2 = arma::square(err);
double rmse = sqrt(arma::mean(err2));
@ -1014,7 +1015,7 @@ void coderate_phaserate_consistence(
// 2. RMSE
arma::vec err;
err = ratediff;
err = std::move(ratediff);
arma::vec err2 = arma::square(err);
double rmse = sqrt(arma::mean(err2));
@ -1098,7 +1099,7 @@ void code_phase_diff(
{
// 2. RMSE
arma::vec err;
err = code_minus_phase;
err = std::move(code_minus_phase);
arma::vec err2 = arma::square(err);
double rmse = sqrt(arma::mean(err2));
@ -1727,6 +1728,8 @@ int main(int argc, char** argv)
{
std::cout << "Running RINEX observables difference tool...\n";
gflags::ParseCommandLineFlags(&argc, &argv, true);
try
{
if (FLAGS_single_diff)
{
if (FLAGS_dupli_sat)
@ -1742,7 +1745,25 @@ int main(int argc, char** argv)
{
RINEX_doublediff(FLAGS_remove_rx_clock_error);
}
}
catch (const gnsstk::Exception& e)
{
std::cerr << e;
gflags::ShutDownCommandLineFlags();
return 1;
}
catch (const std::exception& e)
{
std::cerr << "Exception: " << e.what();
gflags::ShutDownCommandLineFlags();
return 1;
}
catch (...)
{
std::cerr << "Unknown error\n";
gflags::ShutDownCommandLineFlags();
return 1;
}
gflags::ShutDownCommandLineFlags();
return 0;
}