@@ -103,6 +103,7 @@ BLEAdvertisedDevice::BLEAdvertisedDevice(const BLEAdvertisedDevice &other) {
103103 if (m_payload != nullptr ) {
104104 memcpy (m_payload, other.m_payload , m_payloadLength);
105105 } else {
106+ log_e (" Failed to allocate %zu bytes for payload in copy constructor" , m_payloadLength);
106107 m_payloadLength = 0 ;
107108 }
108109 } else {
@@ -153,6 +154,7 @@ BLEAdvertisedDevice &BLEAdvertisedDevice::operator=(const BLEAdvertisedDevice &o
153154 if (m_payload != nullptr ) {
154155 memcpy (m_payload, other.m_payload , m_payloadLength);
155156 } else {
157+ log_e (" Failed to allocate %zu bytes for payload in assignment operator" , m_payloadLength);
156158 m_payloadLength = 0 ;
157159 }
158160 } else {
@@ -422,6 +424,8 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t *payload, size_t total_len)
422424 memcpy (new_payload + m_payloadLength, payload, total_len);
423425 m_payload = new_payload;
424426 m_payloadLength += total_len;
427+ } else {
428+ log_e (" Failed to reallocate %zu bytes for payload (append)" , m_payloadLength + total_len);
425429 }
426430 } else {
427431 // First payload - make a copy since the original buffer may be reused
@@ -430,6 +434,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t *payload, size_t total_len)
430434 memcpy (m_payload, payload, total_len);
431435 m_payloadLength = total_len;
432436 } else {
437+ log_e (" Failed to allocate %zu bytes for payload" , total_len);
433438 m_payloadLength = 0 ;
434439 }
435440 }
@@ -583,7 +588,7 @@ void BLEAdvertisedDevice::setPayload(uint8_t *payload, size_t total_len, bool ap
583588 // Append scan response data to existing advertisement data
584589 uint8_t *new_payload = (uint8_t *)realloc (m_payload, m_payloadLength + total_len);
585590 if (new_payload == nullptr ) {
586- log_e (" Failed to reallocate payload buffer" );
591+ log_e (" Failed to reallocate %zu bytes for payload buffer" , m_payloadLength + total_len );
587592 return ;
588593 }
589594 memcpy (new_payload + m_payloadLength, payload, total_len);
@@ -596,7 +601,7 @@ void BLEAdvertisedDevice::setPayload(uint8_t *payload, size_t total_len, bool ap
596601 }
597602 m_payload = (uint8_t *)malloc (total_len);
598603 if (m_payload == nullptr ) {
599- log_e (" Failed to allocate payload buffer" );
604+ log_e (" Failed to allocate %zu bytes for payload buffer" , total_len );
600605 m_payloadLength = 0 ;
601606 return ;
602607 }
0 commit comments