From 081183c11edd1e1dcbad6c109d3a0498a9987772 Mon Sep 17 00:00:00 2001 From: int_szyk Date: Mon, 23 Sep 2019 12:02:31 +0200 Subject: [PATCH] NFC-URI: fix passing null pointer to a function. Fixes Coverity issue about passing nullptr to memcpy. --- features/nfc/source/nfc/ndef/common/URI.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/features/nfc/source/nfc/ndef/common/URI.cpp b/features/nfc/source/nfc/ndef/common/URI.cpp index a392868843..4761251ce1 100644 --- a/features/nfc/source/nfc/ndef/common/URI.cpp +++ b/features/nfc/source/nfc/ndef/common/URI.cpp @@ -40,15 +40,19 @@ URI::URI(uri_identifier_code_t id, const Span &uri_field) : _uri(uri_field.size() ? new uint8_t[uri_id_code_size + uri_field.size()] : NULL), _uri_size(uri_id_code_size + uri_field.size()) { - _uri[uri_id_index] = id; - memcpy(_uri + uri_field_index, uri_field.data(), uri_field.size()); + if (_uri) { + _uri[uri_id_index] = id; + memcpy(_uri + uri_field_index, uri_field.data(), uri_field.size()); + } } URI::URI(const URI &other) : _uri(other._uri ? new uint8_t[other._uri_size] : NULL), _uri_size(other._uri_size) { - memcpy(_uri, other._uri, other._uri_size); + if (_uri) { + memcpy(_uri, other._uri, other._uri_size); + } } URI::~URI()