2007-02-26 Jonathan Larmour (based on patch from Simon Goldschmidt)

* api_lib.c: Use memcpy in netbuf_copy_partial.
This commit is contained in:
jifl 2007-02-26 19:49:49 +00:00
parent 205520c620
commit de665f7cf9
2 changed files with 17 additions and 11 deletions

View File

@ -27,6 +27,9 @@ HISTORY
++ New features: ++ New features:
2007-02-26 Jonathan Larmour (based on patch from Simon Goldschmidt)
* api_lib.c: Use memcpy in netbuf_copy_partial.
++ Bug fixes: ++ Bug fixes:
(STABLE-1.2.0) (STABLE-1.2.0)

View File

@ -150,7 +150,8 @@ void
netbuf_copy_partial(struct netbuf *buf, void *dataptr, u16_t len, u16_t offset) netbuf_copy_partial(struct netbuf *buf, void *dataptr, u16_t len, u16_t offset)
{ {
struct pbuf *p; struct pbuf *p;
u16_t i, left; u16_t left;
u16_t buf_copy_len;
left = 0; left = 0;
@ -158,18 +159,20 @@ netbuf_copy_partial(struct netbuf *buf, void *dataptr, u16_t len, u16_t offset)
return; return;
} }
/* This implementation is bad. It should use bcopy /* Note some systems use byte copy if dataptr or one of the pbuf payload pointers are unaligned. */
instead. */ for(p = buf->p; len != 0 && p != NULL; p = p->next) {
for(p = buf->p; left < len && p != NULL; p = p->next) {
if (offset != 0 && offset >= p->len) { if (offset != 0 && offset >= p->len) {
/* don't copy from this buffer -> on to the next */
offset -= p->len; offset -= p->len;
} else { } else {
for(i = offset; i < p->len; ++i) { /* copy from this buffer. maybe only partially. */
((u8_t *)dataptr)[left] = ((u8_t *)p->payload)[i]; buf_copy_len = p->len - offset;
if (++left >= len) { if (buf_copy_len > len)
return; buf_copy_len = len;
} /* copy the necessary parts of the buffer */
} memcpy(&((char*)dataptr)[left], &((char*)p->payload)[offset], buf_copy_len);
left += buf_copy_len;
len -= buf_copy_len;
offset = 0; offset = 0;
} }
} }