Skip to content

Commit 081183c

Browse files
committed
NFC-URI: fix passing null pointer to a function.
Fixes Coverity issue about passing nullptr to memcpy.
1 parent 24cb033 commit 081183c

File tree

1 file changed

+7
-3
lines changed
  • features/nfc/source/nfc/ndef/common

1 file changed

+7
-3
lines changed

features/nfc/source/nfc/ndef/common/URI.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,19 @@ URI::URI(uri_identifier_code_t id, const Span<const uint8_t> &uri_field) :
4040
_uri(uri_field.size() ? new uint8_t[uri_id_code_size + uri_field.size()] : NULL),
4141
_uri_size(uri_id_code_size + uri_field.size())
4242
{
43-
_uri[uri_id_index] = id;
44-
memcpy(_uri + uri_field_index, uri_field.data(), uri_field.size());
43+
if (_uri) {
44+
_uri[uri_id_index] = id;
45+
memcpy(_uri + uri_field_index, uri_field.data(), uri_field.size());
46+
}
4547
}
4648

4749
URI::URI(const URI &other) :
4850
_uri(other._uri ? new uint8_t[other._uri_size] : NULL),
4951
_uri_size(other._uri_size)
5052
{
51-
memcpy(_uri, other._uri, other._uri_size);
53+
if (_uri) {
54+
memcpy(_uri, other._uri, other._uri_size);
55+
}
5256
}
5357

5458
URI::~URI()

0 commit comments

Comments
 (0)