From d9308d912da2997b944c80b3dd01b80594c9cce1 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 12 Mar 2019 23:59:43 +0100 Subject: [PATCH] fix: shifting signed 32-bit value by 31 bits is undefined behaviour --- armsrc/lfops.c | 4 ++-- client/cmdlft55xx.c | 6 +++--- client/cmdlfti.c | 2 +- include/at91sam7s512.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/armsrc/lfops.c b/armsrc/lfops.c index b5a905c98..752158929 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -317,7 +317,7 @@ void ReadTItag(void) { // expected for either the low or high frequency if ((samples > (sampleslo - threshold)) && (samples < (sampleslo + threshold))) { // low frequency represents a 1 - shift3 |= (1 << 31); + shift3 |= (1u << 31); } else if ((samples > (sampleshi - threshold)) && (samples < (sampleshi + threshold))) { // high frequency represents a 0 } else { @@ -481,7 +481,7 @@ void AcquireTiType(void) { // unpack buffer for (i = TIBUFLEN - 1; i >= 0; i--) { for (j = 0; j < 32; j++) { - if (buf[i] & (1 << j)) { + if (buf[i] & (1u << j)) { dest[--n] = 1; } else { dest[--n] = -1; diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 91f4a456f..41512c6b9 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -1882,7 +1882,7 @@ int CmdT55xxRecoverPW(const char *Cmd) { // first try fliping each bit in the expected password while (bit < 32) { - curr_password = orig_password ^ (1 << bit); + curr_password = orig_password ^ (1u << bit); found = tryOnePassword(curr_password); if (found == -1) return 0; bit++; @@ -1897,7 +1897,7 @@ int CmdT55xxRecoverPW(const char *Cmd) { // from low bit to high bit bit = 0; while (bit < 32) { - mask += (1 << bit); + mask += (1u << bit); curr_password = orig_password & mask; // if updated mask didn't change the password, don't try it again if (prev_password == curr_password) { @@ -1916,7 +1916,7 @@ int CmdT55xxRecoverPW(const char *Cmd) { bit = 0; mask = 0xffffffff; while (bit < 32) { - mask -= (1 << bit); + mask -= (1u << bit); curr_password = orig_password & mask; // if updated mask didn't change the password, don't try it again if (prev_password == curr_password) { diff --git a/client/cmdlfti.c b/client/cmdlfti.c index 6abb9b5de..5d3c2e399 100644 --- a/client/cmdlfti.c +++ b/client/cmdlfti.c @@ -191,7 +191,7 @@ int CmdTIDemod(const char *Cmd) { bits[i] = '1'; maxPos += highLen; // bitstream arrives lsb first so shift right - shift3 |= (1 << 31); + shift3 |= (1u << 31); } else { bits[i] = '.'; maxPos += lowLen; diff --git a/include/at91sam7s512.h b/include/at91sam7s512.h index f8fa2e8d4..f9f5f69b1 100644 --- a/include/at91sam7s512.h +++ b/include/at91sam7s512.h @@ -375,7 +375,7 @@ typedef struct _AT91S_DBGU { #define AT91C_US_TXBUFE (0x1 << 11) // (DBGU) TXBUFE Interrupt #define AT91C_US_RXBUFF (0x1 << 12) // (DBGU) RXBUFF Interrupt #define AT91C_US_COMM_TX (0x1 << 30) // (DBGU) COMM_TX Interrupt -#define AT91C_US_COMM_RX (0x1 << 31) // (DBGU) COMM_RX Interrupt +#define AT91C_US_COMM_RX (0x1u << 31) // (DBGU) COMM_RX Interrupt // -------- DBGU_IDR : (DBGU Offset: 0xc) Debug Unit Interrupt Disable Register -------- // -------- DBGU_IMR : (DBGU Offset: 0x10) Debug Unit Interrupt Mask Register -------- // -------- DBGU_CSR : (DBGU Offset: 0x14) Debug Unit Channel Status Register --------