From aab3072324785a3e73b66825c55fe87d463098d8 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Tue, 16 Jul 2024 05:13:04 +0100 Subject: [PATCH] hosted/dap_swd: Fix the widening of the sequence data in `dap_swd_seq_in_parity()` to avoid invoking undefined behaviour when shifting the data right --- src/platforms/hosted/dap_swd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/hosted/dap_swd.c b/src/platforms/hosted/dap_swd.c index 7bc64e0ca10..9c6f2a51964 100644 --- a/src/platforms/hosted/dap_swd.c +++ b/src/platforms/hosted/dap_swd.c @@ -167,7 +167,7 @@ static bool dap_swd_seq_in_parity(uint32_t *const result, const size_t clock_cyc uint32_t data = 0; for (size_t offset = 0; offset < clock_cycles; offset += 8U) - data |= sequence.data[offset >> 3U] << offset; + data |= (uint32_t)sequence.data[offset >> 3U] << offset; *result = data; uint8_t parity = calculate_odd_parity(data); return parity == (sequence.data[4] & 1U);