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

Carles Fernandez carles_fernandez-guest at moszumanska.debian.org
Wed Sep 2 00:22:38 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 b8ed6fc7f10b6747695304d26285a3d8cdbe97fb
Author: Carles Fernandez <carles.fernandez at gmail.com>
Date:   Thu May 14 13:06:19 2015 +0200

    fixing coverity issues
---
 .../libs/galileo_e1_signal_processing.cc           |  2 +-
 .../libs/galileo_e5_signal_processing.cc           |  2 +-
 src/algorithms/libs/gps_l2c_signal.cc              | 36 ++++++++++++----------
 .../gnss_block/gps_l2_m_pcps_acquisition_test.cc   |  5 ++-
 4 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/src/algorithms/libs/galileo_e1_signal_processing.cc b/src/algorithms/libs/galileo_e1_signal_processing.cc
index b41de39..77f2d4f 100644
--- a/src/algorithms/libs/galileo_e1_signal_processing.cc
+++ b/src/algorithms/libs/galileo_e1_signal_processing.cc
@@ -153,7 +153,7 @@ void galileo_e1_code_gen_complex_sampled(std::complex<float>* _dest, char _Signa
     const int _codeFreqBasis = Galileo_E1_CODE_CHIP_RATE_HZ; //Hz
     unsigned int _codeLength = Galileo_E1_B_CODE_LENGTH_CHIPS;
     int primary_code_E1_chips[(int)Galileo_E1_B_CODE_LENGTH_CHIPS];
-    _samplesPerCode = round(_fs / (_codeFreqBasis / _codeLength));
+    _samplesPerCode = static_cast<unsigned int>( static_cast<double>(_fs) / (static_cast<double>(_codeFreqBasis )/ static_cast<double>(_codeLength)));
     const int _samplesPerChip = (_cboc == true) ? 12 : 2;
 
     const unsigned int delay = (((int)Galileo_E1_B_CODE_LENGTH_CHIPS - _chip_shift)
diff --git a/src/algorithms/libs/galileo_e5_signal_processing.cc b/src/algorithms/libs/galileo_e5_signal_processing.cc
index 1615bd8..8458108 100644
--- a/src/algorithms/libs/galileo_e5_signal_processing.cc
+++ b/src/algorithms/libs/galileo_e5_signal_processing.cc
@@ -127,4 +127,4 @@ void galileo_e5_a_code_gen_complex_sampled(std::complex<float>* _dest, char _Sig
         }
 
     free(_code);
-}
+
diff --git a/src/algorithms/libs/gps_l2c_signal.cc b/src/algorithms/libs/gps_l2c_signal.cc
index 2922b20..cb0dcc7 100644
--- a/src/algorithms/libs/gps_l2c_signal.cc
+++ b/src/algorithms/libs/gps_l2c_signal.cc
@@ -38,7 +38,7 @@
 
 int32_t gps_l2c_m_shift(int32_t x)
 {
-	return (int32_t)((x>>1)^((x&1)*0445112474));
+	return static_cast<int32_t>((x >> 1)^((x & 1) * 0445112474));
 }
 
 void gps_l2c_m_code(int32_t * _dest, unsigned int _prn)
@@ -56,17 +56,19 @@ void gps_l2c_m_code(int32_t * _dest, unsigned int _prn)
 
 void gps_l2c_m_code_gen_complex(std::complex<float>* _dest, unsigned int _prn)
 {
-	int32_t _code[GPS_L2_M_CODE_LENGTH_CHIPS];
+    int32_t* _code = new int32_t[GPS_L2_M_CODE_LENGTH_CHIPS];
 
-	if (_prn>0 and _prn<51)
-	{
-		gps_l2c_m_code(_code, _prn);
-	}
+    if (_prn > 0 and _prn < 51)
+        {
+            gps_l2c_m_code(_code, _prn);
+        }
 
     for (signed int i = 0; i < GPS_L2_M_CODE_LENGTH_CHIPS; i++)
         {
-        	_dest[i] = std::complex<float>(1.0 - 2.0 * _code[i], 0);
+            _dest[i] = std::complex<float>(1.0 - 2.0 * _code[i], 0.0);
         }
+
+    delete[] _code;
 }
 
 
@@ -75,12 +77,11 @@ void gps_l2c_m_code_gen_complex(std::complex<float>* _dest, unsigned int _prn)
  */
 void gps_l2c_m_code_gen_complex_sampled(std::complex<float>* _dest, unsigned int _prn, signed int _fs)
 {
-	int32_t _code[GPS_L2_M_CODE_LENGTH_CHIPS];
-
-	if (_prn > 0 and _prn < 51)
-	{
-		gps_l2c_m_code(_code, _prn);
-	}
+    int32_t* _code = new int32_t[GPS_L2_M_CODE_LENGTH_CHIPS];
+    if (_prn > 0 and _prn < 51)
+        {
+            gps_l2c_m_code(_code, _prn);
+        }
 
     signed int _samplesPerCode, _codeValueIndex;
     float _ts;
@@ -89,11 +90,11 @@ void gps_l2c_m_code_gen_complex_sampled(std::complex<float>* _dest, unsigned int
     const signed int _codeLength = GPS_L2_M_CODE_LENGTH_CHIPS;
 
     //--- Find number of samples per spreading code ----------------------------
-    _samplesPerCode = round(_fs / (_codeFreqBasis / _codeLength));
+    _samplesPerCode = static_cast<int>(static_cast<double>(_fs) / (static_cast<double>(_codeFreqBasis) / static_cast<double>(_codeLength)));
 
     //--- Find time constants --------------------------------------------------
-    _ts = 1/(float)_fs;   // Sampling period in sec
-    _tc = 1/(float)_codeFreqBasis;  // C/A chip period in sec
+    _ts = 1.0 / static_cast<float>(_fs);   // Sampling period in sec
+    _tc = 1.0 / static_cast<float>(_codeFreqBasis);  // C/A chip period in sec
 
     float aux;
 
@@ -105,7 +106,7 @@ void gps_l2c_m_code_gen_complex_sampled(std::complex<float>* _dest, unsigned int
             // The length of the index array depends on the sampling frequency -
             // number of samples per millisecond (because one C/A code period is one
             // millisecond).
-    	//TODO: Check this formula! Seems to start with an extra sample
+    	    //TODO: Check this formula! Seems to start with an extra sample
 
             // _codeValueIndex = ceil((_ts * ((float)i + 1)) / _tc) - 1;
             aux = (_ts * (i + 1)) / _tc;
@@ -125,6 +126,7 @@ void gps_l2c_m_code_gen_complex_sampled(std::complex<float>* _dest, unsigned int
                     _dest[i] = std::complex<float>(1.0 - 2.0 * _code[_codeValueIndex], 0);; //repeat the chip -> upsample
                 }
         }
+    delete[] _code;
 }
 
 
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 764a059..92579b0 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
@@ -34,6 +34,7 @@
 
 #include <ctime>
 #include <cstdlib>
+#include <cstring>
 #include <iostream>
 #include <boost/chrono.hpp>
 #include <gnuradio/top_block.h>
@@ -98,7 +99,9 @@ void GpsL2MPcpsAcquisitionTest::init()
     gnss_synchro.Channel_ID = 0;
     gnss_synchro.System = 'G';
     std::string signal = "2S";
-    strncpy(gnss_synchro.Signal, signal.c_str(), 3);
+    //strncpy(gnss_synchro.Signal, signal.c_str(), 3);
+    std::memcpy((void*)gnss_synchro.Signal, signal.c_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 = 7;
 
     sampling_freqeuncy_hz  = 5000000;

-- 
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