[hamradio-commits] [gnss-sdr] 73/251: fixing coverity issues

Carles Fernandez carles_fernandez-guest at moszumanska.debian.org
Wed Sep 2 00:22:37 UTC 2015


This is an automated email from the git hooks/post-receive script.

carles_fernandez-guest pushed a commit to branch master
in repository gnss-sdr.

commit d1a1815083fb104ec3f00dfa29cec0083fdb3acb
Author: Carles Fernandez <carles.fernandez at gmail.com>
Date:   Wed May 13 16:40:46 2015 +0200

    fixing coverity issues
---
 .../pcps_quicksync_acquisition_cc.cc               |  2 +-
 .../gps_l1_ca_dll_pll_tracking_cc.cc               |  1 +
 src/core/system_parameters/gps_almanac.cc          | 16 +++++++++++++-
 src/core/system_parameters/gps_ephemeris.cc        | 25 +++++++++++++++-------
 src/core/system_parameters/gps_iono.cc             |  9 +++++++-
 .../system_parameters/gps_navigation_message.cc    |  9 ++++++++
 .../system_parameters/gps_navigation_message.h     |  1 +
 src/core/system_parameters/gps_ref_location.cc     |  3 +++
 src/core/system_parameters/gps_ref_time.cc         |  4 ++++
 src/tests/arithmetic/code_generation_test.cc       | 16 ++++++++------
 src/tests/arithmetic/complex_carrier_test.cc       | 17 +++++++++++----
 src/tests/arithmetic/conjugate_test.cc             |  6 ++++--
 src/tests/arithmetic/magnitude_squared_test.cc     |  6 +++---
 src/tests/arithmetic/multiply_test.cc              | 15 +++++++------
 14 files changed, 96 insertions(+), 34 deletions(-)

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 5030e7e..4841d3e 100644
--- a/src/algorithms/acquisition/gnuradio_blocks/pcps_quicksync_acquisition_cc.cc
+++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_quicksync_acquisition_cc.cc
@@ -381,7 +381,7 @@ int pcps_quicksync_acquisition_cc::general_work(int noutput_items,
 
                     magt = d_magnitude_folded[indext] / (fft_normalization_factor * fft_normalization_factor);
 
-                    delete d_signal_folded;
+                    delete[] d_signal_folded;
 
                     // 4- record the maximum peak and the associated synchronization parameters
                     if (d_mag < magt)
diff --git a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_dll_pll_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_dll_pll_tracking_cc.cc
index f93c4a4..db1abad 100644
--- a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_dll_pll_tracking_cc.cc
+++ b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_dll_pll_tracking_cc.cc
@@ -550,6 +550,7 @@ int Gps_L1_Ca_Dll_Pll_Tracking_cc::general_work (int noutput_items, gr_vector_in
             *d_Prompt = gr_complex(0,0);
             *d_Late = gr_complex(0,0);
 
+            current_synchro_data.System = {'G'};
             current_synchro_data.Flag_valid_pseudorange = false;
             *out[0] = current_synchro_data;
         }
diff --git a/src/core/system_parameters/gps_almanac.cc b/src/core/system_parameters/gps_almanac.cc
index 0d04de4..805b262 100644
--- a/src/core/system_parameters/gps_almanac.cc
+++ b/src/core/system_parameters/gps_almanac.cc
@@ -32,5 +32,19 @@
 
 #include "gps_almanac.h"
 
-Gps_Almanac::Gps_Almanac() {}
+Gps_Almanac::Gps_Almanac() 
+{
+    i_satellite_PRN = 0; 
+    d_Delta_i = 0.0;
+    d_Toa = 0.0;
+    d_M_0 = 0.0;
+    d_e_eccentricity = 0.0;
+    d_sqrt_A = 0.0;
+    d_OMEGA0 = 0.0;
+    d_OMEGA = 0.0;
+    d_OMEGA_DOT = 0.0;
+    i_SV_health = 0;
+    d_A_f0 = 0.0;
+    d_A_f1 = 0.0;
+}
 
diff --git a/src/core/system_parameters/gps_ephemeris.cc b/src/core/system_parameters/gps_ephemeris.cc
index c22715e..37481ee 100644
--- a/src/core/system_parameters/gps_ephemeris.cc
+++ b/src/core/system_parameters/gps_ephemeris.cc
@@ -114,21 +114,30 @@ Gps_Ephemeris::Gps_Ephemeris()
     satelliteBlock[13] = "IIR";
     satelliteBlock[23] = "IIR";
     satelliteBlock[26] = "IIA";
+
+    d_satClkDrift = 0.0;
+    d_dtr = 0.0;
+    d_satpos_X = 0.0;
+    d_satpos_Y = 0.0;
+    d_satpos_Z = 0.0;
+    d_satvel_X = 0.0;
+    d_satvel_Y = 0.0;
+    d_satvel_Z = 0.0;
 }
 
 
 double Gps_Ephemeris::check_t(double time)
 {
     double corrTime;
-    double half_week = 302400;     // seconds
+    double half_week = 302400.0;     // seconds
     corrTime = time;
     if (time > half_week)
         {
-            corrTime = time - 2*half_week;
+            corrTime = time - 2.0 * half_week;
         }
     else if (time < -half_week)
         {
-            corrTime = time + 2*half_week;
+            corrTime = time + 2.0 * half_week;
         }
     return corrTime;
 }
@@ -157,30 +166,30 @@ double Gps_Ephemeris::sv_clock_relativistic_term(double transmitTime)
     double M;
 
     // Restore semi-major axis
-    a = d_sqrt_A*d_sqrt_A;
+    a = d_sqrt_A * d_sqrt_A;
 
     // Time from ephemeris reference epoch
     tk = check_t(transmitTime - d_Toe);
 
     // Computed mean motion
-    n0 = sqrt(GM / (a*a*a));
+    n0 = sqrt(GM / (a * a * a));
     // Corrected mean motion
     n = n0 + d_Delta_n;
     // Mean anomaly
     M = d_M_0 + n * tk;
 
     // Reduce mean anomaly to between 0 and 2pi
-    M = fmod((M + 2*GPS_PI), (2*GPS_PI));
+    M = fmod((M + 2.0 * GPS_PI), (2.0 * GPS_PI));
 
     // Initial guess of eccentric anomaly
     E = M;
 
     // --- Iteratively compute eccentric anomaly ----------------------------
-    for (int ii = 1; ii<20; ii++)
+    for (int ii = 1; ii < 20; ii++)
         {
             E_old   = E;
             E       = M + d_e_eccentricity * sin(E);
-            dE      = fmod(E - E_old, 2*GPS_PI);
+            dE      = fmod(E - E_old, 2.0 * GPS_PI);
             if (fabs(dE) < 1e-12)
                 {
                     //Necessary precision is reached, exit from the loop
diff --git a/src/core/system_parameters/gps_iono.cc b/src/core/system_parameters/gps_iono.cc
index 603f788..48b2b12 100644
--- a/src/core/system_parameters/gps_iono.cc
+++ b/src/core/system_parameters/gps_iono.cc
@@ -35,6 +35,13 @@
 Gps_Iono::Gps_Iono()
 {
     valid = false;
-
+    d_alpha0 = 0.0;
+    d_alpha1 = 0.0;
+    d_alpha2 = 0.0;
+    d_alpha3 = 0.0;
+    d_beta0 = 0.0;
+    d_beta1 = 0.0;
+    d_beta2 = 0.0;
+    d_beta3 = 0.0;
 }
 
diff --git a/src/core/system_parameters/gps_navigation_message.cc b/src/core/system_parameters/gps_navigation_message.cc
index d75ff30..2ab8869 100644
--- a/src/core/system_parameters/gps_navigation_message.cc
+++ b/src/core/system_parameters/gps_navigation_message.cc
@@ -84,6 +84,7 @@ void Gps_Navigation_Message::reset()
     //d_master_clock=0;
     d_dtr = 0;
     d_satClkCorr = 0;
+    d_satClkDrift = 0;
 
     // satellite positions
     d_satpos_X = 0;
@@ -787,6 +788,14 @@ Gps_Ephemeris Gps_Navigation_Message::get_ephemeris()
     ephemeris.b_integrity_status_flag = b_integrity_status_flag;
     ephemeris.b_alert_flag = b_alert_flag;
     ephemeris.b_antispoofing_flag = b_antispoofing_flag;
+    ephemeris.d_satClkDrift = d_satClkDrift;
+    ephemeris.d_dtr = d_dtr;
+    ephemeris.d_satpos_X = d_satpos_X;
+    ephemeris.d_satpos_Y = d_satpos_Y;
+    ephemeris.d_satpos_Z = d_satpos_Z;
+    ephemeris.d_satvel_X = d_satvel_X;
+    ephemeris.d_satvel_Y = d_satvel_Y;
+    ephemeris.d_satvel_Z = d_satvel_Z;
 
     return ephemeris;
 }
diff --git a/src/core/system_parameters/gps_navigation_message.h b/src/core/system_parameters/gps_navigation_message.h
index 2a7e8a5..02f14fb 100644
--- a/src/core/system_parameters/gps_navigation_message.h
+++ b/src/core/system_parameters/gps_navigation_message.h
@@ -150,6 +150,7 @@ public:
     //double d_master_clock;  // GPS transmission time
     double d_satClkCorr;     // GPS clock error
     double d_dtr;            // relativistic clock correction term
+    double d_satClkDrift;
 
     // satellite positions
     double d_satpos_X;       //!< Earth-fixed coordinate x of the satellite [m]. Intersection of the IERS Reference Meridian (IRM) and the plane passing through the origin and normal to the Z-axis.
diff --git a/src/core/system_parameters/gps_ref_location.cc b/src/core/system_parameters/gps_ref_location.cc
index 74eebf0..38f510a 100644
--- a/src/core/system_parameters/gps_ref_location.cc
+++ b/src/core/system_parameters/gps_ref_location.cc
@@ -34,5 +34,8 @@
 Gps_Ref_Location::Gps_Ref_Location()
 {
     valid = false;
+    lat = 0.0;
+    lon = 0.0;
+    uncertainty = 0.0;
 }
 
diff --git a/src/core/system_parameters/gps_ref_time.cc b/src/core/system_parameters/gps_ref_time.cc
index d084fc7..9524f40 100644
--- a/src/core/system_parameters/gps_ref_time.cc
+++ b/src/core/system_parameters/gps_ref_time.cc
@@ -34,5 +34,9 @@
 Gps_Ref_Time::Gps_Ref_Time()
 {
     valid = false;
+    d_TOW = 0.0;
+    d_Week = 0.0;
+    d_tv_sec = 0.0;
+    d_tv_usec = 0.0;
 }
 
diff --git a/src/tests/arithmetic/code_generation_test.cc b/src/tests/arithmetic/code_generation_test.cc
index 2cb56a5..204947e 100644
--- a/src/tests/arithmetic/code_generation_test.cc
+++ b/src/tests/arithmetic/code_generation_test.cc
@@ -53,12 +53,12 @@ TEST(CodeGenGPSL1_Test, CodeGeneration)
         {
             gps_l1_ca_code_gen_complex( _dest,  _prn,  _chip_shift);
         }
-
+    delete[] _dest;
     gettimeofday(&tv, NULL);
     long long int end = tv.tv_sec * 1000000 + tv.tv_usec;
     ASSERT_LE(0, end - begin);
     std::cout << "Generation completed in " << (end - begin) << " microseconds" << std::endl;
-    delete[] _dest;
+    
 
 
     /* std::complex<float>* _dest2 = new std::complex<float>[1023];gettimeofday(&tv, NULL);
@@ -87,10 +87,10 @@ TEST(CodeGenGPSL1Sampled_Test, CodeGeneration)
 {
     signed int _prn = 1;
     unsigned int _chip_shift = 4;
-    int _fs = 8000000;
+    double _fs = 8000000;
     const signed int _codeFreqBasis = 1023000; //Hz
     const signed int _codeLength = 1023;
-    int _samplesPerCode = round(_fs / (_codeFreqBasis / _codeLength));
+    int _samplesPerCode = round(_fs / (double)(_codeFreqBasis / _codeLength));
     std::complex<float>* _dest = new std::complex<float>[_samplesPerCode];
 
     int iterations = 1000;
@@ -106,9 +106,10 @@ TEST(CodeGenGPSL1Sampled_Test, CodeGeneration)
 
     gettimeofday(&tv, NULL);
     long long int end = tv.tv_sec * 1000000 + tv.tv_usec;
+    delete[] _dest;
     ASSERT_LE(0, end - begin);
     std::cout << "Generation completed in " << (end - begin) << " microseconds" << std::endl;
-    delete[] _dest;
+
 
     /* std::complex<float>* _dest2 = new std::complex<float>[_samplesPerCode];
     gettimeofday(&tv, NULL);
@@ -137,7 +138,7 @@ TEST(ComplexCarrier_Test, CodeGeneration)
     double _f = 4000;
     const signed int _codeFreqBasis = 1023000; //Hz
     const signed int _codeLength = 1023;
-    int _samplesPerCode = round(_fs / (_codeFreqBasis / _codeLength));
+    int _samplesPerCode = round(_fs / (double)(_codeFreqBasis / _codeLength));
     std::complex<float>* _dest = new std::complex<float>[_samplesPerCode];
 
     int iterations = 1000;
@@ -153,6 +154,7 @@ TEST(ComplexCarrier_Test, CodeGeneration)
 
     gettimeofday(&tv, NULL);
     long long int end = tv.tv_sec * 1000000 + tv.tv_usec;
+    delete[] _dest; 
     ASSERT_LE(0, end - begin);
     std::cout << "Carrier generation completed in " << (end - begin) << " microseconds" << std::endl;
     
@@ -176,5 +178,5 @@ TEST(ComplexCarrier_Test, CodeGeneration)
 
     std::cout << _dest[10] << "and " << _dest2[10] << std::endl;
     delete[] _dest2;*/
-    delete[] _dest; 
+
 }
diff --git a/src/tests/arithmetic/complex_carrier_test.cc b/src/tests/arithmetic/complex_carrier_test.cc
index fc93bd7..f4e07f6 100644
--- a/src/tests/arithmetic/complex_carrier_test.cc
+++ b/src/tests/arithmetic/complex_carrier_test.cc
@@ -64,15 +64,20 @@ TEST(ComplexCarrier_Test, StandardComplexImplementation)
     std::cout << "A " << FLAGS_size_carrier_test
               << "-length complex carrier in standard C++ (dynamic allocation) generated in " << (end - begin)
               << " microseconds" << std::endl;
-    ASSERT_LE(0, end - begin);
+
     std::complex<float> expected(1,0);
     std::vector<std::complex<float>> mag(FLAGS_size_carrier_test);
     for(int i = 0; i < FLAGS_size_carrier_test; i++)
         {
             mag[i] = output[i] * std::conj(output[i]);
+        }
+    delete[] output;
+    for(int i = 0; i < FLAGS_size_carrier_test; i++)
+        {
             ASSERT_FLOAT_EQ(std::norm(expected), std::norm(mag[i]));
         }
-    delete [] output;
+
+    ASSERT_LE(0, end - begin);
 }
 
 
@@ -127,13 +132,17 @@ TEST(ComplexCarrier_Test, OwnComplexImplementation)
     std::cout << "A " << FLAGS_size_carrier_test
               << "-length complex carrier using fixed point generated in " << (end - begin)
               << " microseconds" << std::endl;
-    ASSERT_LE(0, end - begin);
+
     std::complex<float> expected(1,0);
     std::vector<std::complex<float>> mag(FLAGS_size_carrier_test);
     for(int i = 0; i < FLAGS_size_carrier_test; i++)
         {
             mag[i] = output[i] * std::conj(output[i]);
+        }
+    delete[] output;
+    for(int i = 0; i < FLAGS_size_carrier_test; i++)
+        {
             ASSERT_NEAR(std::norm(expected), std::norm(mag[i]), 0.0001);
         }
-    delete [] output;
+    ASSERT_LE(0, end - begin);
 }
diff --git a/src/tests/arithmetic/conjugate_test.cc b/src/tests/arithmetic/conjugate_test.cc
index 86c498e..9c37257 100644
--- a/src/tests/arithmetic/conjugate_test.cc
+++ b/src/tests/arithmetic/conjugate_test.cc
@@ -59,9 +59,11 @@ TEST(Conjugate_Test, StandardCComplexImplementation)
     std::cout << "Conjugate of a " << FLAGS_size_conjugate_test
               << "-length complex float vector in standard C finished in " << (end - begin)
               << " microseconds" << std::endl;
+
+    delete[] input;
+    delete[] output;
     ASSERT_LE(0, end - begin);
-    delete [] input;
-    delete [] output;
+
 }
 
 
diff --git a/src/tests/arithmetic/magnitude_squared_test.cc b/src/tests/arithmetic/magnitude_squared_test.cc
index 8473343..2b29c58 100644
--- a/src/tests/arithmetic/magnitude_squared_test.cc
+++ b/src/tests/arithmetic/magnitude_squared_test.cc
@@ -58,9 +58,9 @@ TEST(MagnitudeSquared_Test, StandardCComplexImplementation)
     std::cout << "The squared magnitude of a " << FLAGS_size_magnitude_test
               << "-length vector in standard C computed in " << (end - begin)
               << " microseconds" << std::endl;
+    delete[] input;
+    delete[] output;
     ASSERT_LE(0, end - begin);
-    delete [] input;
-    delete [] output;
 }
 
 TEST(MagnitudeSquared_Test, C11ComplexImplementation)
@@ -130,9 +130,9 @@ TEST(MagnitudeSquared_Test, VolkComplexImplementation)
     std::cout <<  "The squared magnitude of a " << FLAGS_size_magnitude_test
               << "-length vector using VOLK computed in " << (end - begin)
               << " microseconds" << std::endl;
-    ASSERT_LE(0, end - begin);
     volk_free(input);
     volk_free(output);
+    ASSERT_LE(0, end - begin);
 }
 
 //            volk_32f_accumulator_s32f(&d_input_power, d_magnitude, d_fft_size);
diff --git a/src/tests/arithmetic/multiply_test.cc b/src/tests/arithmetic/multiply_test.cc
index d307c64..1449f2d 100644
--- a/src/tests/arithmetic/multiply_test.cc
+++ b/src/tests/arithmetic/multiply_test.cc
@@ -59,16 +59,17 @@ TEST(Multiply_Test, StandardCDoubleImplementation)
     std::cout << "Element-wise multiplication of " << FLAGS_size_multiply_test
               << " doubles in standard C finished in " << (end - begin)
               << " microseconds" << std::endl;
-    ASSERT_LE(0, end - begin);
+
     double acc = 0;
     double expected = 0;
     for(int i = 0; i < FLAGS_size_multiply_test; i++)
         {
             acc += output[i];
         }
+    delete[] input;
+    delete[] output;
+    ASSERT_LE(0, end - begin);
     ASSERT_EQ(expected, acc);
-    delete [] input;
-    delete [] output;
 }
 
 
@@ -113,17 +114,17 @@ TEST(Multiply_Test, StandardCComplexImplementation)
     std::cout << "Element-wise multiplication of " << FLAGS_size_multiply_test
               << " complex<float> in standard C finished in " << (end - begin)
               << " microseconds" << std::endl;
-    ASSERT_LE(0, end - begin);
+
     std::complex<float> expected(0,0);
     std::complex<float> result(0,0);
     for(int i = 0; i < FLAGS_size_multiply_test; i++)
          {
              result += output[i];
          }
-
+    delete[] input;
+    delete[] output;
+    ASSERT_LE(0, end - begin);
     ASSERT_EQ(expected, result);
-    delete [] input;
-    delete [] output;
 }
 
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-hamradio/gnss-sdr.git



More information about the pkg-hamradio-commits mailing list