Skip to content

Commit

Permalink
Refactor to avoid uninitialized variables (#26)
Browse files Browse the repository at this point in the history
* Refactor to avoid uninitialized variables

The compiler warned (and errored) because of `message_type` and `header` maybe being uninitialized.

* Fix clang-format

---------

Co-authored-by: Till <[email protected]>
  • Loading branch information
MrEbbinghaus and TillFleisch authored Aug 21, 2024
1 parent 3a84fd1 commit 849f4a6
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions components/LD2450/LD2450.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -173,16 +172,20 @@ namespace esphome::ld2450
}
else
{
skip = true;
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;
}
Expand Down Expand Up @@ -496,4 +499,4 @@ namespace esphome::ld2450

flush();
}
} // namespace esphome::ld2450
} // namespace esphome::ld2450

0 comments on commit 849f4a6

Please sign in to comment.