From 79192a0bbd7ba4bb989f5d9dafe0f6f1d6defc45 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Wed, 13 May 2015 23:50:21 +0200 Subject: [PATCH] fixing coverity issues --- src/algorithms/PVT/libs/galileo_e1_ls_pvt.cc | 34 +++++++++---------- src/algorithms/channel/adapters/channel.cc | 3 +- .../channel/libs/gps_l1_ca_channel_fsm.cc | 5 +++ .../channel/libs/gps_l1_ca_channel_fsm.h | 1 - .../libs/galileo_e5_signal_processing.cc | 11 +++--- .../libs/gps_sdr_signal_processing.cc | 12 +++---- .../adapters/direct_resampler_conditioner.h | 1 - .../adapters/galileo_e1b_telemetry_decoder.cc | 1 + .../adapters/galileo_e5a_telemetry_decoder.cc | 1 + .../adapters/gps_l1_ca_telemetry_decoder.cc | 1 + .../tracking/libs/tracking_2nd_DLL_filter.h | 22 ++++++------ .../tracking/libs/tracking_2nd_PLL_filter.h | 28 +++++++-------- .../tracking/libs/tracking_FLL_PLL_filter.cc | 14 +++++++- .../gps_l2_m_pcps_acquisition_test.cc | 2 +- 14 files changed, 76 insertions(+), 60 deletions(-) diff --git a/src/algorithms/PVT/libs/galileo_e1_ls_pvt.cc b/src/algorithms/PVT/libs/galileo_e1_ls_pvt.cc index 490445a2b..0decedc99 100644 --- a/src/algorithms/PVT/libs/galileo_e1_ls_pvt.cc +++ b/src/algorithms/PVT/libs/galileo_e1_ls_pvt.cc @@ -107,7 +107,7 @@ arma::vec galileo_e1_ls_pvt::rotateSatellite(double traveltime, arma::vec X_sat) R3(1, 2) = 0.0; R3(2, 0) = 0.0; R3(2, 1) = 0.0; - R3(2, 2) = 1; + R3(2, 2) = 1.0; //--- Do the rotation ------------------------------------------------------ arma::vec X_sat_rot; @@ -188,7 +188,7 @@ arma::vec galileo_e1_ls_pvt::leastSquarePos(arma::mat satpos, arma::vec obs, arm togeod(&dphi, &dlambda, &h, 6378137.0, 298.257223563, pos(0), pos(1), pos(2)); //--- Find delay due to troposphere (in meters) - tropo(&trop, sin(d_visible_satellites_El[i] * GALILEO_PI/180.0), h/1000, 1013.0, 293.0, 50.0, 0.0, 0.0, 0.0); + tropo(&trop, sin(d_visible_satellites_El[i] * GALILEO_PI / 180.0), h / 1000.0, 1013.0, 293.0, 50.0, 0.0, 0.0, 0.0); if(trop > 50.0 ) trop = 0.0; } } @@ -238,9 +238,9 @@ bool galileo_e1_ls_pvt::get_PVT(std::map gnss_pseudoranges_map arma::mat satpos = arma::zeros(3, valid_pseudoranges); // satellite positions matrix int Galileo_week_number = 0; - double utc = 0; - double TX_time_corrected_s; - double SV_clock_bias_s = 0; + double utc = 0.0; + double TX_time_corrected_s = 0.0; + double SV_clock_bias_s = 0.0; d_flag_averaging = flag_averaging; @@ -260,7 +260,7 @@ bool galileo_e1_ls_pvt::get_PVT(std::map gnss_pseudoranges_map /*! * \todo Place here the satellite CN0 (power level, or weight factor) */ - W(obs_counter, obs_counter) = 1; + W(obs_counter, obs_counter) = 1.0; // COMMON RX TIME PVT ALGORITHM MODIFICATION (Like RINEX files) // first estimate of transmit time @@ -519,14 +519,14 @@ void galileo_e1_ls_pvt::cart2geo(double X, double Y, double Z, int elipsoid_sele double phi = atan(Z / ((sqrt(X * X + Y * Y) * (1.0 - (2.0 - f[elipsoid_selection])) * f[elipsoid_selection]))); double h = 0.1; - double oldh = 0; + double oldh = 0.0; double N; int iterations = 0; do { oldh = h; N = c / sqrt(1 + ex2 * (cos(phi) * cos(phi))); - phi = atan(Z / ((sqrt(X * X + Y * Y) * (1 - (2 - f[elipsoid_selection]) * f[elipsoid_selection] * N / (N + h) )))); + phi = atan(Z / ((sqrt(X * X + Y * Y) * (1.0 - (2.0 - f[elipsoid_selection]) * f[elipsoid_selection] * N / (N + h) )))); h = sqrt(X * X + Y * Y) / cos(phi) - N; iterations = iterations + 1; if (iterations > 100) @@ -568,17 +568,17 @@ void galileo_e1_ls_pvt::togeod(double *dphi, double *dlambda, double *h, double *h = 0; double tolsq = 1.e-10; // tolerance to accept convergence int maxit = 10; // max number of iterations - double rtd = 180/GPS_PI; + double rtd = 180.0 / GPS_PI; // compute square of eccentricity double esq; if (finv < 1.0E-20) { - esq = 0; + esq = 0.0; } else { - esq = (2 - 1/finv) / finv; + esq = (2.0 - 1.0 / finv) / finv; } // first guess @@ -591,7 +591,7 @@ void galileo_e1_ls_pvt::togeod(double *dphi, double *dlambda, double *h, double } else { - *dlambda = 0; + *dlambda = 0.0; } // correct longitude bound @@ -609,7 +609,7 @@ void galileo_e1_ls_pvt::togeod(double *dphi, double *dlambda, double *h, double } else { - sinphi = 0; + sinphi = 0.0; } *dphi = asin(sinphi); @@ -628,7 +628,7 @@ void galileo_e1_ls_pvt::togeod(double *dphi, double *dlambda, double *h, double double N_phi; double dP; double dZ; - double oneesq = 1 - esq; + double oneesq = 1.0 - esq; for (int i = 0; i < maxit; i++) { @@ -700,7 +700,7 @@ void galileo_e1_ls_pvt::topocent(double *Az, double *El, double *D, arma::vec x, F(1,1) = -sb * sl; F(1,2) = cb * sl; - F(2,0) = 0; + F(2,0) = 0.0; F(2,1) = cb; F(2,2) = sb; @@ -717,8 +717,8 @@ void galileo_e1_ls_pvt::topocent(double *Az, double *El, double *D, arma::vec x, if (hor_dis < 1.0E-20) { - *Az = 0; - *El = 90; + *Az = 0.0; + *El = 90.0; } else { diff --git a/src/algorithms/channel/adapters/channel.cc b/src/algorithms/channel/adapters/channel.cc index be155d3c7..b08084f01 100644 --- a/src/algorithms/channel/adapters/channel.cc +++ b/src/algorithms/channel/adapters/channel.cc @@ -175,7 +175,8 @@ gr::basic_block_sptr Channel::get_right_block() void Channel::set_signal(Gnss_Signal gnss_signal) { gnss_signal_ = gnss_signal; - const char * str = gnss_signal_.get_signal_str().c_str(); // get a C style null terminated string + std::string str_aux = gnss_signal_.get_signal_str(); + const char * str = str_aux.c_str(); // get a C style null terminated string std::memcpy((void*)gnss_synchro_.Signal, str, 3); // copy string into synchro char array: 2 char + null gnss_synchro_.Signal[2] = 0; // make sure that string length is only two characters gnss_synchro_.PRN = gnss_signal_.get_satellite().get_PRN(); diff --git a/src/algorithms/channel/libs/gps_l1_ca_channel_fsm.cc b/src/algorithms/channel/libs/gps_l1_ca_channel_fsm.cc index c7da27667..f6d51b453 100644 --- a/src/algorithms/channel/libs/gps_l1_ca_channel_fsm.cc +++ b/src/algorithms/channel/libs/gps_l1_ca_channel_fsm.cc @@ -115,6 +115,9 @@ public: GpsL1CaChannelFsm::GpsL1CaChannelFsm() { + acq_ = nullptr; + trk_ = nullptr; + channel_ = 0; initiate(); //start the FSM } @@ -123,6 +126,8 @@ GpsL1CaChannelFsm::GpsL1CaChannelFsm() GpsL1CaChannelFsm::GpsL1CaChannelFsm(AcquisitionInterface *acquisition) : acq_(acquisition) { + trk_ = nullptr; + channel_ = 0; initiate(); //start the FSM } diff --git a/src/algorithms/channel/libs/gps_l1_ca_channel_fsm.h b/src/algorithms/channel/libs/gps_l1_ca_channel_fsm.h index ca2f5c6cd..fa5610a95 100644 --- a/src/algorithms/channel/libs/gps_l1_ca_channel_fsm.h +++ b/src/algorithms/channel/libs/gps_l1_ca_channel_fsm.h @@ -85,7 +85,6 @@ public: private: AcquisitionInterface *acq_; TrackingInterface *trk_; - TelemetryDecoderInterface *nav_; boost::shared_ptr queue_; unsigned int channel_; }; diff --git a/src/algorithms/libs/galileo_e5_signal_processing.cc b/src/algorithms/libs/galileo_e5_signal_processing.cc index adf1dfb21..6ef072904 100644 --- a/src/algorithms/libs/galileo_e5_signal_processing.cc +++ b/src/algorithms/libs/galileo_e5_signal_processing.cc @@ -101,11 +101,10 @@ void galileo_e5_a_code_gen_complex_sampled(std::complex* _dest, char _Sig // This function is based on the GNU software GPS for MATLAB in the Kay Borre book unsigned int _samplesPerCode; unsigned int delay; - unsigned int _codeLength = Galileo_E5a_CODE_LENGTH_CHIPS; + const unsigned int _codeLength = Galileo_E5a_CODE_LENGTH_CHIPS; const int _codeFreqBasis = Galileo_E5a_CODE_CHIP_RATE_HZ; //Hz - std::complex* _code; - _code = new std::complex[_codeLength]; + std::complex* _code = new std::complex[_codeLength]; galileo_e5_a_code_gen_complex_primary(_code , _prn , _Signal); @@ -118,8 +117,8 @@ void galileo_e5_a_code_gen_complex_sampled(std::complex* _dest, char _Sig std::complex* _resampled_signal; if (posix_memalign((void**)&_resampled_signal, 16, _samplesPerCode * sizeof(gr_complex)) == 0){}; resampler(_code, _resampled_signal, _codeFreqBasis, _fs, _codeLength, _samplesPerCode); //resamples code to fs - delete[] _code; - _code = _resampled_signal; + //delete[] _code; + memcpy (_code, _resampled_signal, _codeLength); } for (unsigned int i = 0; i < _samplesPerCode; i++) @@ -127,5 +126,5 @@ void galileo_e5_a_code_gen_complex_sampled(std::complex* _dest, char _Sig _dest[(i + delay) % _samplesPerCode] = _code[i]; } - free(_code); + delete[] _code; } diff --git a/src/algorithms/libs/gps_sdr_signal_processing.cc b/src/algorithms/libs/gps_sdr_signal_processing.cc index e4de19b49..bd05354b5 100644 --- a/src/algorithms/libs/gps_sdr_signal_processing.cc +++ b/src/algorithms/libs/gps_sdr_signal_processing.cc @@ -38,8 +38,6 @@ auto auxCeil = [](float x){ return static_cast(static_cast((x)+1)); } void gps_l1_ca_code_gen_complex(std::complex* _dest, signed int _prn, unsigned int _chip_shift) { - - const unsigned int _code_length = 1023; bool G1[_code_length]; bool G2[_code_length]; @@ -135,14 +133,14 @@ void gps_l1_ca_code_gen_complex_sampled(std::complex* _dest, unsigned int const signed int _codeLength = 1023; //--- Find number of samples per spreading code ---------------------------- - _samplesPerCode = round(_fs / (_codeFreqBasis / _codeLength)); + _samplesPerCode = static_cast(static_cast(_fs) / static_cast(_codeFreqBasis / _codeLength)); //--- Find time constants -------------------------------------------------- - _ts = 1/(float)_fs; // Sampling period in sec - _tc = 1/(float)_codeFreqBasis; // C/A chip period in sec - gps_l1_ca_code_gen_complex(_code,_prn, _chip_shift); //generate C/A code 1 sample per chip + _ts = 1.0 / static_cast(_fs); // Sampling period in sec + _tc = 1.0 / static_cast(_codeFreqBasis); // C/A chip period in sec + gps_l1_ca_code_gen_complex(_code, _prn, _chip_shift); //generate C/A code 1 sample per chip - for (signed int i=0; i<_samplesPerCode; i++) + for (signed int i = 0; i < _samplesPerCode; i++) { //=== Digitizing ======================================================= diff --git a/src/algorithms/resampler/adapters/direct_resampler_conditioner.h b/src/algorithms/resampler/adapters/direct_resampler_conditioner.h index 2e3bc31f5..246ec58b8 100644 --- a/src/algorithms/resampler/adapters/direct_resampler_conditioner.h +++ b/src/algorithms/resampler/adapters/direct_resampler_conditioner.h @@ -75,7 +75,6 @@ private: unsigned int out_stream_; std::string item_type_; size_t item_size_; - unsigned long long samples_; bool dump_; std::string dump_filename_; double sample_freq_in_; diff --git a/src/algorithms/telemetry_decoder/adapters/galileo_e1b_telemetry_decoder.cc b/src/algorithms/telemetry_decoder/adapters/galileo_e1b_telemetry_decoder.cc index 6f018c8a6..89e5b2658 100644 --- a/src/algorithms/telemetry_decoder/adapters/galileo_e1b_telemetry_decoder.cc +++ b/src/algorithms/telemetry_decoder/adapters/galileo_e1b_telemetry_decoder.cc @@ -76,6 +76,7 @@ GalileoE1BTelemetryDecoder::GalileoE1BTelemetryDecoder(ConfigurationInterface* c telemetry_decoder_->set_iono_queue(&global_galileo_iono_queue); telemetry_decoder_->set_almanac_queue(&global_galileo_almanac_queue); telemetry_decoder_->set_utc_model_queue(&global_galileo_utc_model_queue); + channel_ = 0; } diff --git a/src/algorithms/telemetry_decoder/adapters/galileo_e5a_telemetry_decoder.cc b/src/algorithms/telemetry_decoder/adapters/galileo_e5a_telemetry_decoder.cc index 4f1f55af5..01251f6fe 100644 --- a/src/algorithms/telemetry_decoder/adapters/galileo_e5a_telemetry_decoder.cc +++ b/src/algorithms/telemetry_decoder/adapters/galileo_e5a_telemetry_decoder.cc @@ -82,6 +82,7 @@ GalileoE5aTelemetryDecoder::GalileoE5aTelemetryDecoder(ConfigurationInterface* c telemetry_decoder_->set_utc_model_queue(&global_galileo_utc_model_queue); DLOG(INFO) << "global navigation message queue assigned to telemetry_decoder ("<< telemetry_decoder_->unique_id() << ")"; + channel_ = 0; } diff --git a/src/algorithms/telemetry_decoder/adapters/gps_l1_ca_telemetry_decoder.cc b/src/algorithms/telemetry_decoder/adapters/gps_l1_ca_telemetry_decoder.cc index 701fa77a2..516154965 100644 --- a/src/algorithms/telemetry_decoder/adapters/gps_l1_ca_telemetry_decoder.cc +++ b/src/algorithms/telemetry_decoder/adapters/gps_l1_ca_telemetry_decoder.cc @@ -80,6 +80,7 @@ GpsL1CaTelemetryDecoder::GpsL1CaTelemetryDecoder(ConfigurationInterface* configu int decimation_factor = configuration->property(role + ".decimation_factor", 1); telemetry_decoder_->set_decimation(decimation_factor); DLOG(INFO) << "global navigation message queue assigned to telemetry_decoder ("<< telemetry_decoder_->unique_id() << ")"; + channel_ = 0; } diff --git a/src/algorithms/tracking/libs/tracking_2nd_DLL_filter.h b/src/algorithms/tracking/libs/tracking_2nd_DLL_filter.h index 7bd58c427..f39a88919 100644 --- a/src/algorithms/tracking/libs/tracking_2nd_DLL_filter.h +++ b/src/algorithms/tracking/libs/tracking_2nd_DLL_filter.h @@ -49,20 +49,20 @@ class Tracking_2nd_DLL_filter { private: // PLL filter parameters - float d_tau1_code; - float d_tau2_code; - float d_pdi_code; - float d_dllnoisebandwidth; - float d_dlldampingratio; - float d_old_code_error; - float d_old_code_nco; + float d_tau1_code = 0; + float d_tau2_code = 0; + float d_pdi_code = 0; + float d_dllnoisebandwidth = 0; + float d_dlldampingratio = 0; + float d_old_code_error = 0; + float d_old_code_nco = 0; void calculate_lopp_coef(float* tau1,float* tau2, float lbw, float zeta, float k); public: - void set_DLL_BW(float dll_bw_hz); //! Set DLL filter bandwidth [Hz] - void set_pdi(float pdi_code); //! Set Summation interval for code [s] - void initialize(); //! Start tracking with acquisition information - float get_code_nco(float DLL_discriminator); //! Numerically controlled oscillator + void set_DLL_BW(float dll_bw_hz); //! Set DLL filter bandwidth [Hz] + void set_pdi(float pdi_code); //! Set Summation interval for code [s] + void initialize(); //! Start tracking with acquisition information + float get_code_nco(float DLL_discriminator); //! Numerically controlled oscillator Tracking_2nd_DLL_filter(float pdi_code); Tracking_2nd_DLL_filter(); ~Tracking_2nd_DLL_filter(); diff --git a/src/algorithms/tracking/libs/tracking_2nd_PLL_filter.h b/src/algorithms/tracking/libs/tracking_2nd_PLL_filter.h index 95911cf50..4a774ce65 100644 --- a/src/algorithms/tracking/libs/tracking_2nd_PLL_filter.h +++ b/src/algorithms/tracking/libs/tracking_2nd_PLL_filter.h @@ -48,26 +48,26 @@ class Tracking_2nd_PLL_filter { private: // PLL filter parameters - float d_tau1_carr; - float d_tau2_carr; - float d_pdi_carr; + float d_tau1_carr = 0; + float d_tau2_carr = 0; + float d_pdi_carr = 0; - float d_pllnoisebandwidth; - float d_plldampingratio; + float d_pllnoisebandwidth = 0; + float d_plldampingratio = 0; - float d_old_carr_error; - float d_old_carr_nco; + float d_old_carr_error = 0; + float d_old_carr_nco = 0; void calculate_lopp_coef(float* tau1,float* tau2, float lbw, float zeta, float k); public: - void set_PLL_BW(float pll_bw_hz); //! Set PLL loop bandwidth [Hz] - void set_pdi(float pdi_carr); //! Set Summation interval for code [s] - void initialize(); - float get_carrier_nco(float PLL_discriminator); - Tracking_2nd_PLL_filter(float pdi_carr); - Tracking_2nd_PLL_filter(); - ~Tracking_2nd_PLL_filter(); + void set_PLL_BW(float pll_bw_hz); //! Set PLL loop bandwidth [Hz] + void set_pdi(float pdi_carr); //! Set Summation interval for code [s] + void initialize(); + float get_carrier_nco(float PLL_discriminator); + Tracking_2nd_PLL_filter(float pdi_carr); + Tracking_2nd_PLL_filter(); + ~Tracking_2nd_PLL_filter(); }; #endif diff --git a/src/algorithms/tracking/libs/tracking_FLL_PLL_filter.cc b/src/algorithms/tracking/libs/tracking_FLL_PLL_filter.cc index dd0871334..f08558170 100644 --- a/src/algorithms/tracking/libs/tracking_FLL_PLL_filter.cc +++ b/src/algorithms/tracking/libs/tracking_FLL_PLL_filter.cc @@ -124,7 +124,19 @@ float Tracking_FLL_PLL_filter::get_carrier_error(float FLL_discriminator, float Tracking_FLL_PLL_filter::Tracking_FLL_PLL_filter () -{} +{ + d_order = 0; + d_pll_w = 0; + d_pll_w0p3 = 0; + d_pll_w0f2 = 0; + d_pll_x = 0; + d_pll_a2 = 0; + d_pll_w0f = 0; + d_pll_a3 = 0; + d_pll_w0p2 = 0; + d_pll_b3 = 0; + d_pll_w0p = 0; +} Tracking_FLL_PLL_filter::~Tracking_FLL_PLL_filter () {} diff --git a/src/tests/gnss_block/gps_l2_m_pcps_acquisition_test.cc b/src/tests/gnss_block/gps_l2_m_pcps_acquisition_test.cc index c3daac5d9..764a0599e 100644 --- a/src/tests/gnss_block/gps_l2_m_pcps_acquisition_test.cc +++ b/src/tests/gnss_block/gps_l2_m_pcps_acquisition_test.cc @@ -98,7 +98,7 @@ void GpsL2MPcpsAcquisitionTest::init() gnss_synchro.Channel_ID = 0; gnss_synchro.System = 'G'; std::string signal = "2S"; - strcpy(gnss_synchro.Signal,signal.c_str()); + strncpy(gnss_synchro.Signal, signal.c_str(), 3); gnss_synchro.PRN = 7; sampling_freqeuncy_hz = 5000000;