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:
2007-02-26 Jonathan Larmour (based on patch from Simon Goldschmidt)
* api_lib.c: Use memcpy in netbuf_copy_partial.
++ Bug fixes:
(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)
{
struct pbuf *p;
u16_t i, left;
u16_t left;
u16_t buf_copy_len;
left = 0;
@ -158,18 +159,20 @@ netbuf_copy_partial(struct netbuf *buf, void *dataptr, u16_t len, u16_t offset)
return;
}
/* This implementation is bad. It should use bcopy
instead. */
for(p = buf->p; left < len && p != NULL; p = p->next) {
/* Note some systems use byte copy if dataptr or one of the pbuf payload pointers are unaligned. */
for(p = buf->p; len != 0 && p != NULL; p = p->next) {
if (offset != 0 && offset >= p->len) {
/* don't copy from this buffer -> on to the next */
offset -= p->len;
} else {
for(i = offset; i < p->len; ++i) {
((u8_t *)dataptr)[left] = ((u8_t *)p->payload)[i];
if (++left >= len) {
return;
}
}
} else {
/* copy from this buffer. maybe only partially. */
buf_copy_len = p->len - offset;
if (buf_copy_len > len)
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;
}
}