From 35852c7efbb437427c14d1de5704e842efe78f78 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 18 Jul 2019 22:57:45 +0200 Subject: [PATCH] clang-tidy fixes Reduce number of hicpp-signed-bitwise warnings See https://rules.sonarsource.com/c/RSPEC-854 --- src/algorithms/libs/gnss_signal_processing.cc | 2 ++ .../libs/libswiftcnav/bits.c | 30 +++++++++---------- .../libs/libswiftcnav/cnav_msg.c | 2 +- .../telemetry_decoder/libs/libswiftcnav/edc.c | 10 +++---- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/algorithms/libs/gnss_signal_processing.cc b/src/algorithms/libs/gnss_signal_processing.cc index 63a244d8b..38f606d93 100644 --- a/src/algorithms/libs/gnss_signal_processing.cc +++ b/src/algorithms/libs/gnss_signal_processing.cc @@ -154,6 +154,8 @@ void hex_to_binary_converter(gsl::span _dest, char _from) _dest[2] = -1; _dest[3] = -1; break; + default: + break; } } diff --git a/src/algorithms/telemetry_decoder/libs/libswiftcnav/bits.c b/src/algorithms/telemetry_decoder/libs/libswiftcnav/bits.c index 3544aad03..df25601c5 100644 --- a/src/algorithms/telemetry_decoder/libs/libswiftcnav/bits.c +++ b/src/algorithms/telemetry_decoder/libs/libswiftcnav/bits.c @@ -51,11 +51,11 @@ static const uint8_t BITN[16] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4} */ uint8_t parity(uint32_t x) { - x ^= x >> 16; - x ^= x >> 8; - x ^= x >> 4; - x &= 0xF; - return (0x6996 >> x) & 1; + x ^= x >> 16U; + x ^= x >> 8U; + x ^= x >> 4U; + x &= 0xFU; + return (0x6996U >> x) & 1U; } @@ -74,7 +74,7 @@ uint32_t getbitu(const uint8_t *buff, uint32_t pos, uint8_t len) uint32_t i = 0; for (i = pos; i < pos + len; i++) { - bits = (bits << 1) + + bits = (bits << 1U) + ((buff[i / 8] >> (7 - i % 8)) & 1U); } @@ -121,7 +121,7 @@ void setbitu(uint8_t *buff, uint32_t pos, uint32_t len, uint32_t data) return; } uint32_t i = 0; - for (i = pos; i < pos + len; i++, mask >>= 1) + for (i = pos; i < pos + len; i++, mask >>= 1U) { if (data & mask) { @@ -246,10 +246,10 @@ void bitcopy(void *dst, uint32_t dst_index, const void *src, uint32_t src_index, uint8_t count_bits_u64(uint64_t v, uint8_t bv) { uint8_t r = 0; - int i = 0; + uint32_t i = 0; for (i = 0; i < 16; i++) { - r += BITN[(v >> (i * 4)) & 0xf]; + r += BITN[(v >> (i * 4U)) & 0xFU]; } return bv == 1 ? r : 64 - r; } @@ -265,10 +265,10 @@ uint8_t count_bits_u64(uint64_t v, uint8_t bv) uint8_t count_bits_u32(uint32_t v, uint8_t bv) { uint8_t r = 0; - int i = 0; + uint32_t i = 0; for (i = 0; i < 8; i++) { - r += BITN[(v >> (i * 4)) & 0xf]; + r += BITN[(v >> (i * 4U)) & 0xFU]; } return bv == 1 ? r : 32 - r; } @@ -284,10 +284,10 @@ uint8_t count_bits_u32(uint32_t v, uint8_t bv) uint8_t count_bits_u16(uint16_t v, uint8_t bv) { uint8_t r = 0; - int i = 0; + uint32_t i = 0; for (i = 0; i < 4; i++) { - r += BITN[(v >> (i * 4)) & 0xf]; + r += BITN[(v >> (i * 4U)) & 0xFU]; } return bv == 1 ? r : 16 - r; } @@ -303,10 +303,10 @@ uint8_t count_bits_u16(uint16_t v, uint8_t bv) uint8_t count_bits_u8(uint8_t v, uint8_t bv) { uint8_t r = 0; - int i = 0; + uint32_t i = 0; for (i = 0; i < 2; i++) { - r += BITN[(v >> (i * 4)) & 0xf]; + r += BITN[(v >> (i * 4U)) & 0xFU]; } return bv == 1 ? r : 8 - r; } diff --git a/src/algorithms/telemetry_decoder/libs/libswiftcnav/cnav_msg.c b/src/algorithms/telemetry_decoder/libs/libswiftcnav/cnav_msg.c index 260237d40..271fc6504 100644 --- a/src/algorithms/telemetry_decoder/libs/libswiftcnav/cnav_msg.c +++ b/src/algorithms/telemetry_decoder/libs/libswiftcnav/cnav_msg.c @@ -106,7 +106,7 @@ static uint32_t _cnav_extract_crc(const cnav_v27_part_t *part) GPS_CNAV_MSG_CRC_LENGTH); if (part->invert) { - crc ^= 0xFFFFFF; + crc ^= 0xFFFFFFU; } return crc; } diff --git a/src/algorithms/telemetry_decoder/libs/libswiftcnav/edc.c b/src/algorithms/telemetry_decoder/libs/libswiftcnav/edc.c index 7bb1e644b..06aa471f4 100644 --- a/src/algorithms/telemetry_decoder/libs/libswiftcnav/edc.c +++ b/src/algorithms/telemetry_decoder/libs/libswiftcnav/edc.c @@ -93,7 +93,7 @@ uint32_t crc24q(const uint8_t *buf, uint32_t len, uint32_t crc) uint32_t i = 0; for (i = 0; i < len; i++) { - crc = ((crc << 8) & 0xFFFFFF) ^ CRC24QTAB[((crc >> 16) ^ buf[i]) & 0xff]; + crc = ((crc << 8U) & 0xFFFFFFU) ^ CRC24QTAB[((crc >> 16U) ^ buf[i]) & 0xFFU]; } return crc; } @@ -122,21 +122,21 @@ uint32_t crc24q_bits(uint32_t crc, const uint8_t *buf, uint32_t n_bits, bool inv uint32_t i = 0; for (i = 0; i < n_bits / 8; ++i) { - acc = (acc << 8) | *buf++; + acc = (acc << 8U) | *buf++; if (invert) { acc ^= 0xFFU; } b = (acc >> shift) & 0xFFU; - crc = ((crc << 8) & 0xFFFFFFU) ^ CRC24QTAB[((crc >> 16) ^ b) & 0xFFU]; + crc = ((crc << 8U) & 0xFFFFFFU) ^ CRC24QTAB[((crc >> 16U) ^ b) & 0xFFU]; } - acc = (acc << 8) | *buf; + acc = (acc << 8U) | *buf; if (invert) { acc ^= 0xFFU; } b = (acc >> shift) & 0xFFU; - crc = ((crc << 8) & 0xFFFFFFU) ^ CRC24QTAB[((crc >> 16) ^ b) & 0xFFU]; + crc = ((crc << 8U) & 0xFFFFFFU) ^ CRC24QTAB[((crc >> 16U) ^ b) & 0xFFU]; return crc; }