26
26
27
27
# include " NimBLEAttValue.h"
28
28
29
+ static const char * LOG_TAG = " NimBLEAttValue" ;
30
+
29
31
// Default constructor implementation.
30
32
NimBLEAttValue::NimBLEAttValue (uint16_t init_len, uint16_t max_len)
31
33
: m_attr_value{static_cast <uint8_t *>(calloc (init_len + 1 , 1 ))},
@@ -38,6 +40,9 @@ NimBLEAttValue::NimBLEAttValue(uint16_t init_len, uint16_t max_len)
38
40
# endif
39
41
{
40
42
NIMBLE_CPP_DEBUG_ASSERT (m_attr_value);
43
+ if (m_attr_value == nullptr ) {
44
+ NIMBLE_LOGE (LOG_TAG, " Failed to calloc ctx" );
45
+ }
41
46
}
42
47
43
48
// Value constructor implementation.
@@ -57,6 +62,10 @@ NimBLEAttValue::~NimBLEAttValue() {
57
62
// Move assignment operator implementation.
58
63
NimBLEAttValue& NimBLEAttValue::operator =(NimBLEAttValue&& source) {
59
64
if (this != &source) {
65
+ if (m_attr_value == nullptr ) {
66
+ NIMBLE_LOGE (LOG_TAG, " Move assign nullptr" );
67
+ return *this ;
68
+ }
60
69
free (m_attr_value);
61
70
m_attr_value = source.m_attr_value ;
62
71
m_attr_max_len = source.m_attr_max_len ;
@@ -81,6 +90,10 @@ NimBLEAttValue& NimBLEAttValue::operator=(const NimBLEAttValue& source) {
81
90
void NimBLEAttValue::deepCopy (const NimBLEAttValue& source) {
82
91
uint8_t * res = static_cast <uint8_t *>(realloc (m_attr_value, source.m_capacity + 1 ));
83
92
NIMBLE_CPP_DEBUG_ASSERT (res);
93
+ if (res == nullptr ) {
94
+ NIMBLE_LOGE (LOG_TAG, " Failed to realloc deepCopy" );
95
+ return ;
96
+ }
84
97
85
98
ble_npl_hw_enter_critical ();
86
99
m_attr_value = res;
@@ -106,7 +119,7 @@ NimBLEAttValue& NimBLEAttValue::append(const uint8_t* value, uint16_t len) {
106
119
}
107
120
108
121
if ((m_attr_len + len) > m_attr_max_len) {
109
- NIMBLE_LOGE (" NimBLEAttValue " , " val > max, len=%u, max=%u" , len, m_attr_max_len);
122
+ NIMBLE_LOGE (LOG_TAG , " val > max, len=%u, max=%u" , len, m_attr_max_len);
110
123
return *this ;
111
124
}
112
125
@@ -117,6 +130,10 @@ NimBLEAttValue& NimBLEAttValue::append(const uint8_t* value, uint16_t len) {
117
130
m_capacity = new_len;
118
131
}
119
132
NIMBLE_CPP_DEBUG_ASSERT (res);
133
+ if (res == nullptr ) {
134
+ NIMBLE_LOGE (LOG_TAG, " Failed to realloc append" );
135
+ return *this ;
136
+ }
120
137
121
138
# if CONFIG_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED
122
139
time_t t = time (nullptr );
0 commit comments