From 8482c7aeb4631f547932437ae1b4cc8521453b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ebbinghaus?= Date: Wed, 21 Aug 2024 15:38:22 +0200 Subject: [PATCH] Refactor to avoid uninitialized variables The compiler warned (and errored) because of `message_type` and `header` maybe being uninitialized. --- components/LD2450/LD2450.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/components/LD2450/LD2450.cpp b/components/LD2450/LD2450.cpp index 789e220..e6f859e 100644 --- a/components/LD2450/LD2450.cpp +++ b/components/LD2450/LD2450.cpp @@ -158,7 +158,6 @@ namespace esphome::ld2450 { // Try to read the header and abort on mismatch const uint8_t *header; - bool skip = false; uint8_t message_type; uint8_t first_byte = read(); if (first_byte == update_header[0]) @@ -171,18 +170,19 @@ namespace esphome::ld2450 header = config_header; message_type = 2; } - else - { - skip = true; - } + else continue; - for (int i = 1; i < 4 && !skip; i++) + bool header_match = true; + for (int i = 1; i < 4; i++) { if (read() != header[i]) - skip = true; + { + header_match = false; + break; + } } - if (!skip) + if (header_match) // Flag successful header reading peek_status_ = message_type; } @@ -496,4 +496,4 @@ namespace esphome::ld2450 flush(); } -} // namespace esphome::ld2450 \ No newline at end of file +} // namespace esphome::ld2450