Skip to content

Commit a8e1215

Browse files
Fix remaining use-auto clang-tidy warning in test_api_rx_edge.cpp
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2af0b13 commit a8e1215

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

tests/src/test_api_rx_edge.cpp

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,6 @@ static void test_rx_v1_multiframe_2frame_classic()
215215
// For v1 multiframe CRC, compute over all payload bytes, then the CRC residue is checked.
216216
// The library accumulates crc_add(seed, payload_of_each_frame) where the last frame includes padding+crc.
217217
// For the residue to be 0, we compute CRC over the payload, then append the CRC big-endian.
218-
uint16_t crc = crc16_ccitt(0xFFFFU, payload, 8U);
219-
220218
// Frame 1: 7 payload bytes + tail.
221219
uint_least8_t frame1[8];
222220
std::memcpy(frame1, payload, 7U);
@@ -231,10 +229,10 @@ static void test_rx_v1_multiframe_2frame_classic()
231229
// The CRC covers: all payload(8) + padding(4) bytes, then the CRC result is appended.
232230
// Recompute: crc_over_all = crc16(0xFFFF, payload(8) + padding(4))
233231
const uint_least8_t padding[4] = { 0, 0, 0, 0 };
234-
crc = crc16_ccitt(0xFFFFU, payload, 8U);
232+
uint16_t crc = crc16_ccitt(0xFFFFU, payload, 8U);
235233
crc = crc16_ccitt(crc, padding, 4U);
236-
const uint_least8_t crc_hi = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
237-
const uint_least8_t crc_lo = static_cast<uint_least8_t>(crc & 0xFFU);
234+
const auto crc_hi = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
235+
const auto crc_lo = static_cast<uint_least8_t>(crc & 0xFFU);
238236

239237
uint_least8_t frame2[8];
240238
frame2[0] = payload[7]; // last payload byte
@@ -297,8 +295,8 @@ static void test_rx_v1_multiframe_3frame()
297295
const uint_least8_t pad[4] = { 0, 0, 0, 0 };
298296
uint16_t crc = crc16_ccitt(0xFFFFU, payload, 15U);
299297
crc = crc16_ccitt(crc, pad, 4U);
300-
const uint_least8_t crc_hi = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
301-
const uint_least8_t crc_lo = static_cast<uint_least8_t>(crc & 0xFFU);
298+
const auto crc_hi = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
299+
const auto crc_lo = static_cast<uint_least8_t>(crc & 0xFFU);
302300

303301
uint_least8_t frame1[8];
304302
std::memcpy(frame1, payload, 7U);
@@ -371,8 +369,8 @@ static void test_rx_v1_multiframe_fd()
371369
const uint_least8_t pad[52] = {};
372370
uint16_t crc = crc16_ccitt(0xFFFFU, payload, 70U);
373371
crc = crc16_ccitt(crc, pad, 52U);
374-
const uint_least8_t crc_hi = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
375-
const uint_least8_t crc_lo = static_cast<uint_least8_t>(crc & 0xFFU);
372+
const auto crc_hi = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
373+
const auto crc_lo = static_cast<uint_least8_t>(crc & 0xFFU);
376374

377375
// Frame 1 (64 bytes).
378376
uint_least8_t frame1[64];
@@ -407,9 +405,9 @@ static void test_rx_v1_multiframe_fd()
407405
// we can choose the exact frame size. Let me use a compact last frame (no padding).
408406

409407
// Recompute CRC without padding.
410-
crc = crc16_ccitt(0xFFFFU, payload, 70U);
411-
const uint_least8_t crc_hi2 = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
412-
const uint_least8_t crc_lo2 = static_cast<uint_least8_t>(crc & 0xFFU);
408+
crc = crc16_ccitt(0xFFFFU, payload, 70U);
409+
const auto crc_hi2 = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
410+
const auto crc_lo2 = static_cast<uint_least8_t>(crc & 0xFFU);
413411

414412
// Frame 2 (10 bytes): 7 payload + CRC(2) + tail.
415413
uint_least8_t frame2b[10];
@@ -457,8 +455,8 @@ static void test_rx_multiframe_crc_error()
457455
crc = crc16_ccitt(crc, pad, 4U);
458456

459457
// Corrupt the CRC by flipping the low byte.
460-
const uint_least8_t bad_crc_hi = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
461-
const uint_least8_t bad_crc_lo = static_cast<uint_least8_t>((crc & 0xFFU) ^ 0x01U); // flipped bit
458+
const auto bad_crc_hi = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
459+
const auto bad_crc_lo = static_cast<uint_least8_t>((crc & 0xFFU) ^ 0x01U); // flipped bit
462460

463461
uint_least8_t frame1[8];
464462
std::memcpy(frame1, payload, 7U);
@@ -508,8 +506,8 @@ static void test_rx_multiframe_single_bit_flip()
508506
const uint_least8_t pad[4] = {};
509507
uint16_t crc = crc16_ccitt(0xFFFFU, payload, 8U);
510508
crc = crc16_ccitt(crc, pad, 4U);
511-
const uint_least8_t crc_hi = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
512-
const uint_least8_t crc_lo = static_cast<uint_least8_t>(crc & 0xFFU);
509+
const auto crc_hi = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
510+
const auto crc_lo = static_cast<uint_least8_t>(crc & 0xFFU);
513511

514512
// Frame 1 with a single bit flip in byte 3.
515513
uint_least8_t frame1[8];
@@ -597,8 +595,8 @@ static void test_rx_extent_truncation_multiframe()
597595
const uint_least8_t pad[4] = {};
598596
uint16_t crc = crc16_ccitt(0xFFFFU, payload, 8U);
599597
crc = crc16_ccitt(crc, pad, 4U);
600-
const uint_least8_t crc_hi = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
601-
const uint_least8_t crc_lo = static_cast<uint_least8_t>(crc & 0xFFU);
598+
const auto crc_hi = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
599+
const auto crc_lo = static_cast<uint_least8_t>(crc & 0xFFU);
602600

603601
uint_least8_t frame1[8];
604602
std::memcpy(frame1, payload, 7U);
@@ -853,8 +851,8 @@ static void test_rx_priority_preemption_interleaved()
853851
const uint32_t can_id_hi = make_v1v1_msg_can_id(canard_prio_fast, 2100U, 10U);
854852

855853
// Build frames for both transfers.
856-
uint16_t crc_lo = crc16_ccitt(crc16_ccitt(0xFFFFU, payload_lo, 8U), pad, 4U);
857-
uint16_t crc_hi = crc16_ccitt(crc16_ccitt(0xFFFFU, payload_hi, 8U), pad, 4U);
854+
const uint16_t crc_lo = crc16_ccitt(crc16_ccitt(0xFFFFU, payload_lo, 8U), pad, 4U);
855+
const uint16_t crc_hi = crc16_ccitt(crc16_ccitt(0xFFFFU, payload_hi, 8U), pad, 4U);
858856

859857
uint_least8_t f1_lo[8];
860858
uint_least8_t f2_lo[8];
@@ -1019,8 +1017,8 @@ static void test_rx_wrong_toggle_rejected()
10191017
const uint_least8_t pad[4] = {};
10201018
uint16_t crc = crc16_ccitt(0xFFFFU, payload, 8U);
10211019
crc = crc16_ccitt(crc, pad, 4U);
1022-
const uint_least8_t crc_hi = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
1023-
const uint_least8_t crc_lo = static_cast<uint_least8_t>(crc & 0xFFU);
1020+
const auto crc_hi = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
1021+
const auto crc_lo = static_cast<uint_least8_t>(crc & 0xFFU);
10241022

10251023
// Frame 1 (SOT): toggle=1 (correct for v1).
10261024
uint_least8_t frame1[8];
@@ -1067,8 +1065,8 @@ static void test_rx_interface_affinity()
10671065
const uint_least8_t pad[4] = {};
10681066
uint16_t crc = crc16_ccitt(0xFFFFU, payload, 8U);
10691067
crc = crc16_ccitt(crc, pad, 4U);
1070-
const uint_least8_t crc_hi = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
1071-
const uint_least8_t crc_lo = static_cast<uint_least8_t>(crc & 0xFFU);
1068+
const auto crc_hi = static_cast<uint_least8_t>((static_cast<unsigned>(crc) >> 8U) & 0xFFU);
1069+
const auto crc_lo = static_cast<uint_least8_t>(crc & 0xFFU);
10721070

10731071
uint_least8_t frame1[8];
10741072
std::memcpy(frame1, payload, 7U);
@@ -1161,7 +1159,7 @@ static void test_rx_v0_multiframe_roundtrip()
11611159
const uint32_t can_id = make_v0_msg_can_id(canard_prio_nominal, 1000U, 10U);
11621160

11631161
// v0 multiframe CRC: computed over the user payload only, then prepended little-endian.
1164-
uint16_t v0crc = crc16_ccitt(crc_seed, payload, 8U);
1162+
const uint16_t v0crc = crc16_ccitt(crc_seed, payload, 8U);
11651163

11661164
// Total stream data: [crc_lo, crc_hi, payload[0..7]] = 10 bytes.
11671165
// Classic CAN MTU=8, 7 data bytes per frame + tail byte.

0 commit comments

Comments
 (0)