Skip to content

Commit 25eb59f

Browse files
Xie,Qieriknyquist
Xie,Qi
authored andcommitted
fix KW issue for class BLEDescriptor, BLECharacteristic and port.c
1 parent 6a4d381 commit 25eb59f

File tree

6 files changed

+119
-11
lines changed

6 files changed

+119
-11
lines changed

libraries/BLE/src/BLECharacteristic.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,44 @@ BLECharacteristic::BLECharacteristic(BLECharacteristicImp *characteristicImp,
4646
_value_size = characteristicImp->valueSize();
4747
}
4848

49+
BLECharacteristic::BLECharacteristic(const BLECharacteristic& rhs)
50+
{
51+
unsigned char *_value = (unsigned char*)malloc(rhs._value_size);
52+
if (_value)
53+
{
54+
memcpy(_value, rhs._value, rhs._value_size);
55+
_value_size = rhs._value_size;
56+
memcpy(_uuid_cstr, rhs._uuid_cstr, sizeof(_uuid_cstr));
57+
_properties = rhs._properties;
58+
_event_handlers = rhs._event_handlers;
59+
_internal = rhs._internal;
60+
_bledev = BLEDevice(&rhs._bledev);
61+
}
62+
}
63+
64+
BLECharacteristic& BLECharacteristic::operator= (const BLECharacteristic& rhs)
65+
{
66+
if (this != &rhs)
67+
{
68+
if (_value)
69+
{
70+
free(_value);
71+
}
72+
_value = (unsigned char*)malloc(rhs._value_size);
73+
if (_value)
74+
{
75+
memcpy(_value, rhs._value, rhs._value_size);
76+
_value_size = rhs._value_size;
77+
memcpy(_uuid_cstr, rhs._uuid_cstr, sizeof(_uuid_cstr));
78+
_properties = rhs._properties;
79+
_event_handlers = rhs._event_handlers;
80+
_internal = rhs._internal;
81+
_bledev = BLEDevice(&rhs._bledev);
82+
}
83+
}
84+
return *this;
85+
}
86+
4987
BLECharacteristic::~BLECharacteristic()
5088
{
5189
if (_value)

libraries/BLE/src/BLECharacteristic.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ class BLECharacteristic: public BLEAttributeWithValue
8484
unsigned char properties,
8585
const char* value);
8686

87+
BLECharacteristic(const BLECharacteristic&);
88+
89+
BLECharacteristic& operator=(const BLECharacteristic&);
90+
8791
virtual ~BLECharacteristic();
8892

8993
/**

libraries/BLE/src/BLEDescriptor.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,40 @@ BLEDescriptor::BLEDescriptor(const char* uuid,
6666
BLEDescriptor(uuid, (const unsigned char*)value, strlen(value))
6767
{}
6868

69+
BLEDescriptor::BLEDescriptor(const BLEDescriptor& rhs)
70+
{
71+
unsigned char *_value = (unsigned char*)malloc(rhs._value_size);
72+
if (_value)
73+
{
74+
memcpy(_value, rhs._value, rhs._value_size);
75+
_value_size = rhs._value_size;
76+
memcpy(_uuid_cstr, rhs._uuid_cstr, sizeof(_uuid_cstr));
77+
_properties = rhs._properties;
78+
_bledev = BLEDevice(&rhs._bledev);
79+
}
80+
}
81+
82+
BLEDescriptor& BLEDescriptor::operator= (const BLEDescriptor& rhs)
83+
{
84+
if (this != &rhs)
85+
{
86+
if (_value)
87+
{
88+
free(_value);
89+
}
90+
_value = (unsigned char*)malloc(rhs._value_size);
91+
if (_value)
92+
{
93+
memcpy(_value, rhs._value, rhs._value_size);
94+
_value_size = rhs._value_size;
95+
memcpy(_uuid_cstr, rhs._uuid_cstr, sizeof(_uuid_cstr));
96+
_properties = rhs._properties;
97+
_bledev = BLEDevice(&rhs._bledev);
98+
}
99+
}
100+
return *this;
101+
}
102+
69103
BLEDescriptor::~BLEDescriptor()
70104
{
71105
if (_value)

libraries/BLE/src/BLEDescriptor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class BLEDescriptor
3232
BLEDescriptor(const char* uuid, const char* value); // create a descriptor the specified uuid and string value
3333

3434
BLEDescriptor(BLEDescriptorImp* descriptorImp, const BLEDevice *bleDev);
35+
BLEDescriptor(const BLEDescriptor&);
36+
BLEDescriptor& operator=(const BLEDescriptor&);
3537

3638
virtual ~BLEDescriptor();
3739

libraries/BLE/src/internal/BLEProfileManager.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,12 @@ void BLEProfileManager::serviceDiscoverComplete(const BLEDevice &bledevice)
760760
servicePrevImp->setEndHandle(serviceCurImp->startHandle() - 1);
761761
}
762762

763-
pr_debug(LOG_MODULE_BLE, "Curr: start-%d, end-%d", servicePrevImp->startHandle(), servicePrevImp->endHandle());
763+
if (servicePrevImp)
764+
{
765+
pr_debug(LOG_MODULE_BLE, "Curr: start-%d, end-%d", servicePrevImp->startHandle(), servicePrevImp->endHandle());
766+
}
764767
servicePrevImp = serviceCurImp;
765-
pr_debug(LOG_MODULE_BLE, "Curr: start-%d, end-%d", servicePrevImp->startHandle(), servicePrevImp->endHandle());
768+
pr_debug(LOG_MODULE_BLE, "Curr: start-%d, end-%d", servicePrevImp->startHandle(), servicePrevImp->endHandle());
766769
node = node->next;
767770
}
768771
return;

system/libarc32_arduino101/framework/src/infra/port.c

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ static struct port * get_port(uint16_t port_id)
129129
void port_set_queue(uint16_t port_id, void * queue)
130130
{
131131
struct port * p = get_port(port_id);
132-
p->queue = queue;
132+
if (p)
133+
{
134+
p->queue = queue;
135+
}
133136
}
134137

135138
#ifdef CONFIG_INFRA_IS_MASTER
@@ -176,8 +179,11 @@ uint16_t port_alloc(void *queue)
176179
void port_set_handler(uint16_t port_id, void (*handler)(struct message*, void*), void *param)
177180
{
178181
struct port * port = get_port(port_id);
179-
port->handle_message = handler;
180-
port->handle_param = param;
182+
if (port)
183+
{
184+
port->handle_message = handler;
185+
port->handle_param = param;
186+
}
181187
}
182188

183189
struct message * message_alloc(int size, OS_ERR_TYPE * err)
@@ -193,27 +199,40 @@ struct message * message_alloc(int size, OS_ERR_TYPE * err)
193199
void port_process_message(struct message * msg)
194200
{
195201
struct port * p = get_port(msg->dst_port_id);
196-
if (p->handle_message != NULL) {
202+
if (p && p->handle_message != NULL) {
197203
p->handle_message(msg, p->handle_param);
198204
}
199205
}
200206

201207
void port_set_cpu_id(uint16_t port_id, uint8_t cpu_id)
202208
{
203209
struct port * p = get_port(port_id);
204-
p->cpu_id = cpu_id;
210+
if (p)
211+
{
212+
p->cpu_id = cpu_id;
213+
}
205214
}
206215

207216
void port_set_port_id(uint16_t port_id)
208217
{
209218
struct port * p = get_port(port_id);
210-
p->id = port_id;
219+
if (p)
220+
{
221+
p->id = port_id;
222+
}
211223
}
212224

213225
uint8_t port_get_cpu_id(uint16_t port_id)
214226
{
215227
struct port * p = get_port(port_id);
216-
return p->cpu_id;
228+
if (p)
229+
{
230+
return p->cpu_id;
231+
}
232+
else
233+
{
234+
return 0;
235+
}
217236
}
218237

219238
#ifdef INFRA_MULTI_CPU_SUPPORT
@@ -258,7 +277,7 @@ int port_send_message(struct message * message)
258277
pr_info(LOG_MODULE_MAIN, "Sending message %p to port %p(q:%p) ret: %d", message, port, port->queue, err);
259278
#endif
260279
struct port *src_port = get_port(MESSAGE_SRC(message));
261-
if (src_port->cpu_id == get_cpu_id()) {
280+
if (src_port && src_port->cpu_id == get_cpu_id()) {
262281
/* We bypass the software queue here and process directly
263282
* due to lack of background thread on this implementation
264283
*/
@@ -278,6 +297,10 @@ int port_send_message(struct message * message)
278297
void message_free(struct message * msg)
279298
{
280299
struct port * port = get_port(MESSAGE_SRC(msg));
300+
if (!port)
301+
{
302+
return;
303+
}
281304
pr_debug(LOG_MODULE_MAIN, "free message %p: port %p[%d] this %d id %d",
282305
msg, port, port->cpu_id, get_cpu_id(), MESSAGE_SRC(msg));
283306
if (port->cpu_id == get_cpu_id()) {
@@ -291,8 +314,12 @@ void message_free(struct message * msg)
291314

292315
int port_send_message(struct message * msg)
293316
{
294-
struct port * port = get_port(MESSAGE_DST(msg));
295317
OS_ERR_TYPE err;
318+
struct port * port = get_port(MESSAGE_DST(msg));
319+
if (!port)
320+
{
321+
return E_OS_ERR_NO_MEMORY;
322+
}
296323
if (src_port->cpu_id == get_cpu_id()) {
297324
/* We bypass the software queue here and process directly
298325
* due to lack of background thread on this implementation

0 commit comments

Comments
 (0)