Skip to content

Commit

Permalink
fix undefined behavior when using ports #406
Browse files Browse the repository at this point in the history
  • Loading branch information
rainerschoe committed Feb 6, 2022
1 parent f3611f4 commit 4dff0bc
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/PJONDefines.h
Expand Up @@ -395,6 +395,14 @@ struct PJONTools {

static void parse_header(const uint8_t *packet, PJON_Packet_Info &info) {
uint8_t index = 0;

// replace passed in info with a fresh instance
// (initializing all values to their defaults)
// This is important, as we conditionally parse some info fields (e.g. Port)
// Those would then be left uninitialized or in an old state corresponding to
// the previous packet:
info = PJON_Packet_Info{};

info.rx.id = packet[index++];
bool extended_length = packet[index] & PJON_EXT_LEN_BIT;
info.header = packet[index++];
Expand Down

0 comments on commit 4dff0bc

Please sign in to comment.