Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fc4a570

Browse filesBrowse files
committed
Fix: do not call "memcpy" if there is a) no data to copy, or the src pointer is null.
1 parent f1ae7d0 commit fc4a570
Copy full SHA for fc4a570

File tree

1 file changed

+6
-3
lines changed
Filter options

1 file changed

+6
-3
lines changed

‎api/CanMsg.h

Copy file name to clipboardExpand all lines: api/CanMsg.h
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class CanMsg : public Printable
4545
, data_length{min(can_data_len, MAX_DATA_LENGTH)}
4646
, data{0}
4747
{
48-
memcpy(data, can_data_ptr, data_length);
48+
if (data_length && can_data_ptr)
49+
memcpy(data, can_data_ptr, data_length);
4950
}
5051

5152
CanMsg() : CanMsg(0, 0, nullptr) { }
@@ -54,7 +55,8 @@ class CanMsg : public Printable
5455
{
5556
this->id = other.id;
5657
this->data_length = other.data_length;
57-
memcpy(this->data, other.data, this->data_length);
58+
if (this->data_length && other.data)
59+
memcpy(this->data, other.data, this->data_length);
5860
}
5961

6062
virtual ~CanMsg() { }
@@ -65,7 +67,8 @@ class CanMsg : public Printable
6567
{
6668
this->id = other.id;
6769
this->data_length = other.data_length;
68-
memcpy(this->data, other.data, this->data_length);
70+
if (this->data_length && other.data)
71+
memcpy(this->data, other.data, this->data_length);
6972
}
7073
return (*this);
7174
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.