From ec9aa207b0e12f04541454c6467bd5c832806c68 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 15 Jul 2019 12:14:39 +0200 Subject: [PATCH] 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. --- .../galileo_telemetry_decoder_gs.cc | 6 ++-- .../gps_l1_ca_telemetry_decoder_gs.cc | 34 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/algorithms/telemetry_decoder/gnuradio_blocks/galileo_telemetry_decoder_gs.cc b/src/algorithms/telemetry_decoder/gnuradio_blocks/galileo_telemetry_decoder_gs.cc index c6f965a04..bd029d005 100644 --- a/src/algorithms/telemetry_decoder/gnuradio_blocks/galileo_telemetry_decoder_gs.cc +++ b/src/algorithms/telemetry_decoder/gnuradio_blocks/galileo_telemetry_decoder_gs.cc @@ -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(mm); // 2^mm + g_encoder[0] = 121; // Polynomial G1 + g_encoder[1] = 91; // Polynomial G2 out0 = static_cast(volk_gnsssdr_malloc(max_states * sizeof(int32_t), volk_gnsssdr_get_alignment())); out1 = static_cast(volk_gnsssdr_malloc(max_states * sizeof(int32_t), volk_gnsssdr_get_alignment())); state0 = static_cast(volk_gnsssdr_malloc(max_states * sizeof(int32_t), volk_gnsssdr_get_alignment())); diff --git a/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_gs.cc b/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_gs.cc index c7104025c..22a72940e 100644 --- a/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_gs.cc +++ b/src/algorithms/telemetry_decoder/gnuradio_blocks/gps_l1_ca_telemetry_decoder_gs.cc @@ -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 } }