mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #3375 from authmillenon/ng_pktbuf/fix/equal-size
ng_pktbuf: handle size == pkt->size case for ng_pktbuf_add()
This commit is contained in:
commit
789744c89d
@ -199,17 +199,17 @@ static ng_pktsnip_t *_pktbuf_add_unsafe(ng_pktsnip_t *pkt, void *data,
|
||||
{
|
||||
ng_pktsnip_t *new_pktsnip;
|
||||
|
||||
new_pktsnip = (ng_pktsnip_t *)_pktbuf_internal_alloc(sizeof(ng_pktsnip_t));
|
||||
DEBUG("pktbuf: allocated (new_pktsnip = %p) ", (void *)new_pktsnip);
|
||||
|
||||
if (new_pktsnip == NULL) {
|
||||
DEBUG("=> failed\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DEBUG("of size %u\n", (unsigned)sizeof(ng_pktsnip_t));
|
||||
|
||||
if (pkt == NULL || pkt->data != data) {
|
||||
new_pktsnip = (ng_pktsnip_t *)_pktbuf_internal_alloc(sizeof(ng_pktsnip_t));
|
||||
DEBUG("pktbuf: allocated (new_pktsnip = %p) ", (void *)new_pktsnip);
|
||||
|
||||
if (new_pktsnip == NULL) {
|
||||
DEBUG("=> failed\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DEBUG("of size %u\n", (unsigned)sizeof(ng_pktsnip_t));
|
||||
|
||||
if ((size != 0) && (!_pktbuf_internal_contains(data))) {
|
||||
new_pktsnip->data = _pktbuf_internal_alloc(size);
|
||||
DEBUG("pktbuf: allocated (new_pktsnip->data = %p) ", new_pktsnip->data);
|
||||
@ -258,6 +258,22 @@ static ng_pktsnip_t *_pktbuf_add_unsafe(ng_pktsnip_t *pkt, void *data,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (size == pkt->size) {
|
||||
DEBUG("pktbuf: size (%u) == pkt->size (%u) => just set new packet "
|
||||
"type and return\n", (unsigned)size, (unsigned)pkt->size);
|
||||
pkt->type = type;
|
||||
return pkt;
|
||||
}
|
||||
|
||||
new_pktsnip = (ng_pktsnip_t *)_pktbuf_internal_alloc(sizeof(ng_pktsnip_t));
|
||||
DEBUG("pktbuf: allocated (new_pktsnip = %p) ", (void *)new_pktsnip);
|
||||
|
||||
if (new_pktsnip == NULL) {
|
||||
DEBUG("=> failed\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DEBUG("of size %u\n", (unsigned)sizeof(ng_pktsnip_t));
|
||||
DEBUG("pktbuf: Adding chunk to %p ", pkt->data);
|
||||
|
||||
if (!_pktbuf_internal_add_pkt(pkt->data)) {
|
||||
|
Loading…
Reference in New Issue
Block a user