1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-14 20:20:35 +00:00

fixing coverity issues

This commit is contained in:
Carles Fernandez 2015-05-14 13:06:19 +02:00
parent 2613bc30e4
commit b8ed6fc7f1
4 changed files with 25 additions and 20 deletions

View File

@ -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 const int _codeFreqBasis = Galileo_E1_CODE_CHIP_RATE_HZ; //Hz
unsigned int _codeLength = Galileo_E1_B_CODE_LENGTH_CHIPS; unsigned int _codeLength = Galileo_E1_B_CODE_LENGTH_CHIPS;
int primary_code_E1_chips[(int)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 int _samplesPerChip = (_cboc == true) ? 12 : 2;
const unsigned int delay = (((int)Galileo_E1_B_CODE_LENGTH_CHIPS - _chip_shift) const unsigned int delay = (((int)Galileo_E1_B_CODE_LENGTH_CHIPS - _chip_shift)

View File

@ -127,4 +127,4 @@ void galileo_e5_a_code_gen_complex_sampled(std::complex<float>* _dest, char _Sig
} }
free(_code); free(_code);
}

View File

@ -38,7 +38,7 @@
int32_t gps_l2c_m_shift(int32_t x) 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) 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) 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) if (_prn > 0 and _prn < 51)
{ {
gps_l2c_m_code(_code, _prn); gps_l2c_m_code(_code, _prn);
} }
for (signed int i = 0; i < GPS_L2_M_CODE_LENGTH_CHIPS; i++) 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) 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]; int32_t* _code = new int32_t[GPS_L2_M_CODE_LENGTH_CHIPS];
if (_prn > 0 and _prn < 51)
if (_prn > 0 and _prn < 51) {
{ gps_l2c_m_code(_code, _prn);
gps_l2c_m_code(_code, _prn); }
}
signed int _samplesPerCode, _codeValueIndex; signed int _samplesPerCode, _codeValueIndex;
float _ts; 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; const signed int _codeLength = GPS_L2_M_CODE_LENGTH_CHIPS;
//--- Find number of samples per spreading code ---------------------------- //--- 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 -------------------------------------------------- //--- Find time constants --------------------------------------------------
_ts = 1/(float)_fs; // Sampling period in sec _ts = 1.0 / static_cast<float>(_fs); // Sampling period in sec
_tc = 1/(float)_codeFreqBasis; // C/A chip period in sec _tc = 1.0 / static_cast<float>(_codeFreqBasis); // C/A chip period in sec
float aux; 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 - // The length of the index array depends on the sampling frequency -
// number of samples per millisecond (because one C/A code period is one // number of samples per millisecond (because one C/A code period is one
// millisecond). // 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; // _codeValueIndex = ceil((_ts * ((float)i + 1)) / _tc) - 1;
aux = (_ts * (i + 1)) / _tc; 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 _dest[i] = std::complex<float>(1.0 - 2.0 * _code[_codeValueIndex], 0);; //repeat the chip -> upsample
} }
} }
delete[] _code;
} }

View File

@ -34,6 +34,7 @@
#include <ctime> #include <ctime>
#include <cstdlib> #include <cstdlib>
#include <cstring>
#include <iostream> #include <iostream>
#include <boost/chrono.hpp> #include <boost/chrono.hpp>
#include <gnuradio/top_block.h> #include <gnuradio/top_block.h>
@ -98,7 +99,9 @@ void GpsL2MPcpsAcquisitionTest::init()
gnss_synchro.Channel_ID = 0; gnss_synchro.Channel_ID = 0;
gnss_synchro.System = 'G'; gnss_synchro.System = 'G';
std::string signal = "2S"; 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; gnss_synchro.PRN = 7;
sampling_freqeuncy_hz = 5000000; sampling_freqeuncy_hz = 5000000;