mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-07 18:12:55 +03:00
pdu.c: fix len returned by coap_get_data() for empty payload
John Carter has provided this (slightly edited) patch to set len to 0 for PDUs that do not contain a payload. This makes this function more robust for callers that do not care about the function result. This change fixes issue 120 [1]. [1] https://github.com/obgm/libcoap/issues/120
This commit is contained in:
1 parent
0c837cdc77
commit
8ee4bb2586
1 file changed
+8
-2
@@ -324,9 +324,15 @@ coap_get_data(coap_pdu_t *pdu, size_t *len, uint8_t **data) {
|
||||
assert(len);
|
||||
assert(data);
|
||||
|
||||
*len = pdu->used_size - (pdu->data - pdu->token);
|
||||
*data = pdu->data;
|
||||
return *data != NULL;
|
||||
if(pdu->data == NULL) {
|
||||
*len = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*len = pdu->used_size - (pdu->data - pdu->token);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef SHORT_ERROR_RESPONSE
|
||||
|
||||
Reference in new issue
Block a user