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

Do not use bitwise operators with signed operands

Use of signed operands with bitwise operators is in some cases subject to undefined or implementation defined behavior. Therefore, bitwise operators should only be used with operands of unsigned integral types.
This commit is contained in:
Carles Fernandez 2019-07-15 12:14:39 +02:00
parent 7436188f34
commit ec9aa207b0
2 changed files with 20 additions and 20 deletions

View File

@ -181,9 +181,9 @@ galileo_telemetry_decoder_gs::galileo_telemetry_decoder_gs(
d_symbol_history.set_capacity(d_required_symbols + 1);
// vars for Viterbi decoder
int32_t max_states = 1 << mm; // 2^mm
g_encoder[0] = 121; // Polynomial G1
g_encoder[1] = 91; // Polynomial G2
int32_t max_states = 1U << static_cast<uint32_t>(mm); // 2^mm
g_encoder[0] = 121; // Polynomial G1
g_encoder[1] = 91; // Polynomial G2
out0 = static_cast<int32_t *>(volk_gnsssdr_malloc(max_states * sizeof(int32_t), volk_gnsssdr_get_alignment()));
out1 = static_cast<int32_t *>(volk_gnsssdr_malloc(max_states * sizeof(int32_t), volk_gnsssdr_get_alignment()));
state0 = static_cast<int32_t *>(volk_gnsssdr_malloc(max_states * sizeof(int32_t), volk_gnsssdr_get_alignment()));

View File

@ -145,18 +145,18 @@ bool gps_l1_ca_telemetry_decoder_gs::gps_word_parityCheck(uint32_t gpsword)
// up bits which are to be XOR'ed together to implement the GPS parity
// check algorithm described in IS-GPS-200E. This avoids lengthy shift-
// and-xor loops.
d1 = gpsword & 0xFBFFBF00;
d2 = _rotl(gpsword, 1) & 0x07FFBF01;
d3 = _rotl(gpsword, 2) & 0xFC0F8100;
d4 = _rotl(gpsword, 3) & 0xF81FFE02;
d5 = _rotl(gpsword, 4) & 0xFC00000E;
d6 = _rotl(gpsword, 5) & 0x07F00001;
d7 = _rotl(gpsword, 6) & 0x00003000;
d1 = gpsword & 0xFBFFBF00U;
d2 = _rotl(gpsword, 1) & 0x07FFBF01U;
d3 = _rotl(gpsword, 2) & 0xFC0F8100U;
d4 = _rotl(gpsword, 3) & 0xF81FFE02U;
d5 = _rotl(gpsword, 4) & 0xFC00000EU;
d6 = _rotl(gpsword, 5) & 0x07F00001U;
d7 = _rotl(gpsword, 6) & 0x00003000U;
t = d1 ^ d2 ^ d3 ^ d4 ^ d5 ^ d6 ^ d7;
// Now XOR the 5 6-bit fields together to produce the 6-bit final result.
parity = t ^ _rotl(t, 6) ^ _rotl(t, 12) ^ _rotl(t, 18) ^ _rotl(t, 24);
parity = parity & 0x3F;
if (parity == (gpsword & 0x3F))
parity = t ^ _rotl(t, 6U) ^ _rotl(t, 12U) ^ _rotl(t, 18U) ^ _rotl(t, 24U);
parity = parity & 0x3FU;
if (parity == (gpsword & 0x3FU))
{
return true;
}
@ -230,19 +230,19 @@ bool gps_l1_ca_telemetry_decoder_gs::decode_subframe()
// Bits 0 to 29 = the GPS data word
// Bits 30 to 31 = 2 LSBs of the GPS word ahead.
// prepare the extended frame [-2 -1 0 ... 30]
if (d_prev_GPS_frame_4bytes & 0x00000001)
if (d_prev_GPS_frame_4bytes & 0x00000001U)
{
GPS_frame_4bytes = GPS_frame_4bytes | 0x40000000;
GPS_frame_4bytes = GPS_frame_4bytes | 0x40000000U;
}
if (d_prev_GPS_frame_4bytes & 0x00000002)
if (d_prev_GPS_frame_4bytes & 0x00000002U)
{
GPS_frame_4bytes = GPS_frame_4bytes | 0x80000000;
GPS_frame_4bytes = GPS_frame_4bytes | 0x80000000U;
}
// Check that the 2 most recently logged words pass parity. Have to first
// invert the data bits according to bit 30 of the previous word.
if (GPS_frame_4bytes & 0x40000000)
if (GPS_frame_4bytes & 0x40000000U)
{
GPS_frame_4bytes ^= 0x3FFFFFC0; // invert the data bits (using XOR)
GPS_frame_4bytes ^= 0x3FFFFFC0U; // invert the data bits (using XOR)
}
// check parity. If ANY word inside the subframe fails the parity, set subframe_synchro_confirmation = false
if (not gps_l1_ca_telemetry_decoder_gs::gps_word_parityCheck(GPS_frame_4bytes))
@ -258,7 +258,7 @@ bool gps_l1_ca_telemetry_decoder_gs::decode_subframe()
}
else
{
GPS_frame_4bytes <<= 1; // shift 1 bit left the telemetry word
GPS_frame_4bytes <<= 1U; // shift 1 bit left the telemetry word
}
}