Skip to content

Commit 65633ce

Browse files
authored
Merge pull request #217 from arduino/fix-wno-null
Fix: do not call "memcpy" if there is a) no data to copy, or b) the src pointer is null.
2 parents f1ae7d0 + fc4a570 commit 65633ce

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

api/CanMsg.h

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy