Skip to content

Commit

Permalink
Fix: do not call "memcpy" if there is a) no data to copy, or the src …
Browse files Browse the repository at this point in the history
…pointer is null.
  • Loading branch information
aentinger committed Sep 26, 2023
1 parent f1ae7d0 commit fc4a570
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions api/CanMsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class CanMsg : public Printable
, data_length{min(can_data_len, MAX_DATA_LENGTH)}
, data{0}
{
memcpy(data, can_data_ptr, data_length);
if (data_length && can_data_ptr)
memcpy(data, can_data_ptr, data_length);
}

CanMsg() : CanMsg(0, 0, nullptr) { }
Expand All @@ -54,7 +55,8 @@ class CanMsg : public Printable
{
this->id = other.id;
this->data_length = other.data_length;
memcpy(this->data, other.data, this->data_length);
if (this->data_length && other.data)
memcpy(this->data, other.data, this->data_length);
}

virtual ~CanMsg() { }
Expand All @@ -65,7 +67,8 @@ class CanMsg : public Printable
{
this->id = other.id;
this->data_length = other.data_length;
memcpy(this->data, other.data, this->data_length);
if (this->data_length && other.data)
memcpy(this->data, other.data, this->data_length);
}
return (*this);
}
Expand Down

0 comments on commit fc4a570

Please sign in to comment.