Skip to content

Commit

Permalink
Refactor to avoid uninitialized variables
Browse files Browse the repository at this point in the history
The compiler warned (and errored) because of `message_type` and `header` maybe being uninitialized.
  • Loading branch information
MrEbbinghaus authored Aug 21, 2024
1 parent 3a84fd1 commit 8482c7a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 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 @@ -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;
}
Expand Down Expand Up @@ -496,4 +496,4 @@ namespace esphome::ld2450

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

0 comments on commit 8482c7a

Please sign in to comment.