mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-01-01 12:00:53 +00:00
Implement a more readable fix for pbuf_memcmp than my last fix
This commit is contained in:
parent
b944ceb89d
commit
ac6b64cf66
@ -1300,29 +1300,30 @@ pbuf_memcmp(struct pbuf* p, u16_t offset, const void* s2, u16_t n)
|
|||||||
{
|
{
|
||||||
u16_t start = offset;
|
u16_t start = offset;
|
||||||
struct pbuf* q = p;
|
struct pbuf* q = p;
|
||||||
|
u16_t i;
|
||||||
|
|
||||||
/* get the correct pbuf */
|
/* pbuf long enough to perform check? */
|
||||||
|
if(p->tot_len < (offset + n)) {
|
||||||
|
return 0xffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get the correct pbuf from chain. We know it succeeds because of p->tot_len check above. */
|
||||||
while ((q != NULL) && (q->len <= start)) {
|
while ((q != NULL) && (q->len <= start)) {
|
||||||
start -= q->len;
|
start -= q->len;
|
||||||
q = q->next;
|
q = q->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return requested data if pbuf is OK */
|
/* return requested data if pbuf is OK */
|
||||||
if ((q != NULL) && (q->len > start)) {
|
|
||||||
u16_t i;
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
|
/* We know pbuf_get_at() succeeds because of p->tot_len check above. */
|
||||||
|
u8_t a = pbuf_get_at(q, start + i);
|
||||||
u8_t b = ((const u8_t*)s2)[i];
|
u8_t b = ((const u8_t*)s2)[i];
|
||||||
int a = pbuf_try_get_at(q, start + i);
|
|
||||||
if (a < 0) {
|
|
||||||
return 0xffff;
|
|
||||||
}
|
|
||||||
if (a != b) {
|
if (a != b) {
|
||||||
return i+1;
|
return i+1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 0xffff;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup pbuf
|
* @ingroup pbuf
|
||||||
|
Loading…
Reference in New Issue
Block a user