diff --git a/api/CanMsg.h b/api/CanMsg.h index dfece0d6..eaa3f0ed 100644 --- a/api/CanMsg.h +++ b/api/CanMsg.h @@ -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) { } @@ -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() { } @@ -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); }