mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-01-12 21:41:28 +00:00
work on -Wconversion...
This commit is contained in:
parent
2b2fa0ed71
commit
debf34ff9c
@ -319,7 +319,7 @@ dhcp_check(struct netif *netif)
|
||||
dhcp->tries++;
|
||||
}
|
||||
msecs = 500;
|
||||
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
|
||||
dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_check(): set request timeout %"U16_F" msecs\n", msecs));
|
||||
}
|
||||
#endif /* DHCP_DOES_ARP_CHECK */
|
||||
@ -396,8 +396,6 @@ dhcp_select(struct netif *netif)
|
||||
|
||||
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, DHCP_STATE_REQUESTING, dhcp->msg_out, DHCP_REQUEST);
|
||||
dhcp_option_trailer(dhcp);
|
||||
/* shrink the pbuf to the actual content length */
|
||||
pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len);
|
||||
|
||||
/* send broadcast to any DHCP server */
|
||||
udp_sendto_if_src(dhcp_pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif, IP4_ADDR_ANY);
|
||||
@ -409,8 +407,8 @@ dhcp_select(struct netif *netif)
|
||||
if (dhcp->tries < 255) {
|
||||
dhcp->tries++;
|
||||
}
|
||||
msecs = (dhcp->tries < 6 ? 1 << dhcp->tries : 60) * 1000;
|
||||
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
|
||||
msecs = (u16_t)((dhcp->tries < 6 ? 1 << dhcp->tries : 60) * 1000);
|
||||
dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_select(): set request timeout %"U16_F" msecs\n", msecs));
|
||||
return result;
|
||||
}
|
||||
@ -554,7 +552,7 @@ dhcp_t1_timeout(struct netif *netif)
|
||||
/* Calculate next timeout */
|
||||
if (((dhcp->t2_timeout - dhcp->lease_used) / 2) >= ((60 + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS))
|
||||
{
|
||||
dhcp->t1_renew_time = ((dhcp->t2_timeout - dhcp->lease_used) / 2);
|
||||
dhcp->t1_renew_time = (u16_t)((dhcp->t2_timeout - dhcp->lease_used) / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -581,7 +579,7 @@ dhcp_t2_timeout(struct netif *netif)
|
||||
/* Calculate next timeout */
|
||||
if (((dhcp->t0_timeout - dhcp->lease_used) / 2) >= ((60 + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS))
|
||||
{
|
||||
dhcp->t2_rebind_time = ((dhcp->t0_timeout - dhcp->lease_used) / 2);
|
||||
dhcp->t2_rebind_time = (u16_t)((dhcp->t0_timeout - dhcp->lease_used) / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -832,8 +830,6 @@ dhcp_inform(struct netif *netif)
|
||||
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, &dhcp, DHCP_STATE_INFORMING, dhcp.msg_out, DHCP_INFORM);
|
||||
dhcp_option_trailer(&dhcp);
|
||||
|
||||
pbuf_realloc(dhcp.p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp.options_out_len);
|
||||
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_inform: INFORMING\n"));
|
||||
|
||||
udp_sendto_if(dhcp_pcb, dhcp.p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif);
|
||||
@ -944,8 +940,6 @@ dhcp_decline(struct netif *netif)
|
||||
|
||||
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, DHCP_STATE_BACKING_OFF, dhcp->msg_out, DHCP_DECLINE);
|
||||
dhcp_option_trailer(dhcp);
|
||||
/* resize pbuf to reflect true size of options */
|
||||
pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len);
|
||||
|
||||
/* per section 4.4.4, broadcast DECLINE messages */
|
||||
udp_sendto_if_src(dhcp_pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif, IP4_ADDR_ANY);
|
||||
@ -959,7 +953,7 @@ dhcp_decline(struct netif *netif)
|
||||
dhcp->tries++;
|
||||
}
|
||||
msecs = 10*1000;
|
||||
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
|
||||
dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_decline(): set request timeout %"U16_F" msecs\n", msecs));
|
||||
return result;
|
||||
}
|
||||
@ -996,9 +990,6 @@ dhcp_discover(struct netif *netif)
|
||||
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, DHCP_STATE_SELECTING, dhcp->msg_out, DHCP_DISCOVER);
|
||||
dhcp_option_trailer(dhcp);
|
||||
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_discover: realloc()ing\n"));
|
||||
pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len);
|
||||
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, DHCP_SERVER_PORT)\n"));
|
||||
udp_sendto_if_src(dhcp_pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif, IP4_ADDR_ANY);
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_discover: deleting()ing\n"));
|
||||
@ -1016,8 +1007,8 @@ dhcp_discover(struct netif *netif)
|
||||
autoip_start(netif);
|
||||
}
|
||||
#endif /* LWIP_DHCP_AUTOIP_COOP */
|
||||
msecs = (dhcp->tries < 6 ? 1 << dhcp->tries : 60) * 1000;
|
||||
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
|
||||
msecs = (u16_t)((dhcp->tries < 6 ? 1 << dhcp->tries : 60) * 1000);
|
||||
dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_discover(): set request timeout %"U16_F" msecs\n", msecs));
|
||||
return result;
|
||||
}
|
||||
@ -1167,8 +1158,6 @@ dhcp_renew(struct netif *netif)
|
||||
/* append DHCP message trailer */
|
||||
dhcp_option_trailer(dhcp);
|
||||
|
||||
pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len);
|
||||
|
||||
udp_sendto_if(dhcp_pcb, dhcp->p_out, &dhcp->server_ip_addr, DHCP_SERVER_PORT, netif);
|
||||
dhcp_delete_msg(dhcp);
|
||||
|
||||
@ -1180,8 +1169,8 @@ dhcp_renew(struct netif *netif)
|
||||
dhcp->tries++;
|
||||
}
|
||||
/* back-off on retries, but to a maximum of 20 seconds */
|
||||
msecs = dhcp->tries < 10 ? dhcp->tries * 2000 : 20 * 1000;
|
||||
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
|
||||
msecs = (u16_t)(dhcp->tries < 10 ? dhcp->tries * 2000 : 20 * 1000);
|
||||
dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_renew(): set request timeout %"U16_F" msecs\n", msecs));
|
||||
return result;
|
||||
}
|
||||
@ -1219,8 +1208,6 @@ dhcp_rebind(struct netif *netif)
|
||||
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, DHCP_STATE_REBINDING, dhcp->msg_out, DHCP_DISCOVER);
|
||||
dhcp_option_trailer(dhcp);
|
||||
|
||||
pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len);
|
||||
|
||||
/* broadcast to server */
|
||||
udp_sendto_if(dhcp_pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif);
|
||||
dhcp_delete_msg(dhcp);
|
||||
@ -1231,8 +1218,8 @@ dhcp_rebind(struct netif *netif)
|
||||
if (dhcp->tries < 255) {
|
||||
dhcp->tries++;
|
||||
}
|
||||
msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000;
|
||||
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
|
||||
msecs = (u16_t)(dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000);
|
||||
dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_rebind(): set request timeout %"U16_F" msecs\n", msecs));
|
||||
return result;
|
||||
}
|
||||
@ -1268,8 +1255,6 @@ dhcp_reboot(struct netif *netif)
|
||||
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, DHCP_STATE_REBOOTING, dhcp->msg_out, DHCP_REQUEST);
|
||||
dhcp_option_trailer(dhcp);
|
||||
|
||||
pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len);
|
||||
|
||||
/* broadcast to server */
|
||||
udp_sendto_if(dhcp_pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif);
|
||||
dhcp_delete_msg(dhcp);
|
||||
@ -1280,8 +1265,8 @@ dhcp_reboot(struct netif *netif)
|
||||
if (dhcp->tries < 255) {
|
||||
dhcp->tries++;
|
||||
}
|
||||
msecs = dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000;
|
||||
dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
|
||||
msecs = (u16_t)(dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000);
|
||||
dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_reboot(): set request timeout %"U16_F" msecs\n", msecs));
|
||||
return result;
|
||||
}
|
||||
@ -1332,8 +1317,6 @@ dhcp_release_and_stop(struct netif *netif)
|
||||
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, dhcp->state, dhcp->msg_out, DHCP_RELEASE);
|
||||
dhcp_option_trailer(dhcp);
|
||||
|
||||
pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len);
|
||||
|
||||
udp_sendto_if(dhcp_pcb, dhcp->p_out, &server_ip_addr, DHCP_SERVER_PORT, netif);
|
||||
dhcp_delete_msg(dhcp);
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_release: RELEASED, DHCP_STATE_OFF\n"));
|
||||
@ -1508,8 +1491,8 @@ dhcp_parse_reply(struct dhcp *dhcp, struct pbuf *p)
|
||||
again:
|
||||
q = p;
|
||||
while ((q != NULL) && (options_idx >= q->len)) {
|
||||
options_idx -= q->len;
|
||||
options_idx_max -= q->len;
|
||||
options_idx = (u16_t)(options_idx - q->len);
|
||||
options_idx_max = (u16_t)(options_idx_max - q->len);
|
||||
q = q->next;
|
||||
}
|
||||
if (q == NULL) {
|
||||
@ -1524,7 +1507,11 @@ again:
|
||||
u8_t len;
|
||||
u8_t decode_len = 0;
|
||||
int decode_idx = -1;
|
||||
u16_t val_offset = offset + 2;
|
||||
u16_t val_offset = (u16_t)(offset + 2);
|
||||
if (val_offset < offset) {
|
||||
/* overflow */
|
||||
return ERR_BUF;
|
||||
}
|
||||
/* len byte might be in the next pbuf */
|
||||
if ((offset + 1) < q->len) {
|
||||
len = options[offset + 1];
|
||||
@ -1604,7 +1591,11 @@ again:
|
||||
op, len, q, val_offset);
|
||||
break;
|
||||
}
|
||||
offset += len + 2;
|
||||
if (offset + len + 2 > 0xFFFF) {
|
||||
/* overflow */
|
||||
return ERR_BUF;
|
||||
}
|
||||
offset = (u16_t)(offset + len + 2);
|
||||
if (decode_len > 0) {
|
||||
u32_t value = 0;
|
||||
u16_t copy_len;
|
||||
@ -1617,11 +1608,17 @@ decode_next:
|
||||
}
|
||||
if (decode_len > 4) {
|
||||
/* decode more than one u32_t */
|
||||
u16_t next_val_offset;
|
||||
LWIP_ERROR("decode_len %% 4 == 0", decode_len % 4 == 0, return ERR_VAL;);
|
||||
dhcp_got_option(dhcp, decode_idx);
|
||||
dhcp_set_option_value(dhcp, decode_idx, lwip_htonl(value));
|
||||
decode_len -= 4;
|
||||
val_offset += 4;
|
||||
decode_len = (u8_t)(decode_len - 4);
|
||||
next_val_offset = (u16_t)(val_offset + 4);
|
||||
if (next_val_offset < val_offset) {
|
||||
/* overflow */
|
||||
return ERR_BUF;
|
||||
}
|
||||
val_offset = next_val_offset;
|
||||
decode_idx++;
|
||||
goto decode_next;
|
||||
} else if (decode_len == 4) {
|
||||
@ -1635,8 +1632,8 @@ decode_next:
|
||||
}
|
||||
}
|
||||
if (offset >= q->len) {
|
||||
offset -= q->len;
|
||||
offset_max -= q->len;
|
||||
offset = (u16_t)(offset - q->len);
|
||||
offset_max = (u16_t)(offset_max - q->len);
|
||||
if ((offset < offset_max) && offset_max) {
|
||||
q = q->next;
|
||||
LWIP_ERROR("next pbuf was null", q != NULL, return ERR_VAL;);
|
||||
@ -1951,6 +1948,8 @@ dhcp_option_trailer(struct dhcp *dhcp)
|
||||
/* add a fill/padding byte */
|
||||
dhcp->msg_out->options[dhcp->options_out_len++] = 0;
|
||||
}
|
||||
/* shrink the pbuf to the actual content length */
|
||||
pbuf_realloc(dhcp->p_out, (u16_t)(sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len));
|
||||
}
|
||||
|
||||
/** check if DHCP supplied netif->ip_addr
|
||||
|
@ -469,16 +469,16 @@ mem_free(void *rmem)
|
||||
* Shrink memory returned by mem_malloc().
|
||||
*
|
||||
* @param rmem pointer to memory allocated by mem_malloc the is to be shrinked
|
||||
* @param newsize required size after shrinking (needs to be smaller than or
|
||||
* @param new_size required size after shrinking (needs to be smaller than or
|
||||
* equal to the previous size)
|
||||
* @return for compatibility reasons: is always == rmem, at the moment
|
||||
* or NULL if newsize is > old size, in which case rmem is NOT touched
|
||||
* or freed!
|
||||
*/
|
||||
void *
|
||||
mem_trim(void *rmem, mem_size_t newsize)
|
||||
mem_trim(void *rmem, mem_size_t new_size)
|
||||
{
|
||||
mem_size_t size;
|
||||
mem_size_t size, newsize;
|
||||
mem_size_t ptr, ptr2;
|
||||
struct mem *mem, *mem2;
|
||||
/* use the FREE_PROTECT here: it protects with sem OR SYS_ARCH_PROTECT */
|
||||
@ -486,17 +486,16 @@ mem_trim(void *rmem, mem_size_t newsize)
|
||||
|
||||
/* Expand the size of the allocated memory region so that we can
|
||||
adjust for alignment. */
|
||||
newsize = LWIP_MEM_ALIGN_SIZE(newsize);
|
||||
newsize = (mem_size_t)LWIP_MEM_ALIGN_SIZE(new_size);
|
||||
if ((newsize > MEM_SIZE_ALIGNED) || (newsize < new_size)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (newsize < MIN_SIZE_ALIGNED) {
|
||||
/* every data block must be at least MIN_SIZE_ALIGNED long */
|
||||
newsize = MIN_SIZE_ALIGNED;
|
||||
}
|
||||
|
||||
if (newsize > MEM_SIZE_ALIGNED) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LWIP_ASSERT("mem_trim: legal memory", (u8_t *)rmem >= (u8_t *)ram &&
|
||||
(u8_t *)rmem < (u8_t *)ram_end);
|
||||
|
||||
@ -512,7 +511,7 @@ mem_trim(void *rmem, mem_size_t newsize)
|
||||
/* ... and its offset pointer */
|
||||
ptr = (mem_size_t)((u8_t *)mem - ram);
|
||||
|
||||
size = mem->next - ptr - SIZEOF_STRUCT_MEM;
|
||||
size = (mem_size_t)((mem_size_t)(mem->next - ptr) - SIZEOF_STRUCT_MEM);
|
||||
LWIP_ASSERT("mem_trim can only shrink memory", newsize <= size);
|
||||
if (newsize > size) {
|
||||
/* not supported */
|
||||
@ -533,7 +532,7 @@ mem_trim(void *rmem, mem_size_t newsize)
|
||||
/* remember the old next pointer */
|
||||
next = mem2->next;
|
||||
/* create new struct mem which is moved directly after the shrinked mem */
|
||||
ptr2 = ptr + SIZEOF_STRUCT_MEM + newsize;
|
||||
ptr2 = (mem_size_t)(ptr + SIZEOF_STRUCT_MEM + newsize);
|
||||
if (lfree == mem2) {
|
||||
lfree = (struct mem *)(void *)&ram[ptr2];
|
||||
}
|
||||
@ -561,7 +560,7 @@ mem_trim(void *rmem, mem_size_t newsize)
|
||||
* @todo we could leave out MIN_SIZE_ALIGNED. We would create an empty
|
||||
* region that couldn't hold data, but when mem->next gets freed,
|
||||
* the 2 regions would be combined, resulting in more free memory */
|
||||
ptr2 = ptr + SIZEOF_STRUCT_MEM + newsize;
|
||||
ptr2 = (mem_size_t)(ptr + SIZEOF_STRUCT_MEM + newsize);
|
||||
mem2 = (struct mem *)(void *)&ram[ptr2];
|
||||
if (mem2 < lfree) {
|
||||
lfree = mem2;
|
||||
@ -592,38 +591,38 @@ mem_trim(void *rmem, mem_size_t newsize)
|
||||
/**
|
||||
* Allocate a block of memory with a minimum of 'size' bytes.
|
||||
*
|
||||
* @param size is the minimum size of the requested block in bytes.
|
||||
* @param size_in is the minimum size of the requested block in bytes.
|
||||
* @return pointer to allocated memory or NULL if no free memory was found.
|
||||
*
|
||||
* Note that the returned value will always be aligned (as defined by MEM_ALIGNMENT).
|
||||
*/
|
||||
void *
|
||||
mem_malloc(mem_size_t size)
|
||||
mem_malloc(mem_size_t size_in)
|
||||
{
|
||||
mem_size_t ptr, ptr2;
|
||||
mem_size_t ptr, ptr2, size;
|
||||
struct mem *mem, *mem2;
|
||||
#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
|
||||
u8_t local_mem_free_count = 0;
|
||||
#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
|
||||
LWIP_MEM_ALLOC_DECL_PROTECT();
|
||||
|
||||
if (size == 0) {
|
||||
if (size_in == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Expand the size of the allocated memory region so that we can
|
||||
adjust for alignment. */
|
||||
size = LWIP_MEM_ALIGN_SIZE(size);
|
||||
size = (mem_size_t)LWIP_MEM_ALIGN_SIZE(size_in);
|
||||
if ((size > MEM_SIZE_ALIGNED) ||
|
||||
(size < size_in)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (size < MIN_SIZE_ALIGNED) {
|
||||
/* every data block must be at least MIN_SIZE_ALIGNED long */
|
||||
size = MIN_SIZE_ALIGNED;
|
||||
}
|
||||
|
||||
if (size > MEM_SIZE_ALIGNED) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* protect the heap from concurrent access */
|
||||
sys_mutex_lock(&mem_mutex);
|
||||
LWIP_MEM_ALLOC_PROTECT();
|
||||
@ -668,7 +667,7 @@ mem_malloc(mem_size_t size)
|
||||
* region that couldn't hold data, but when mem->next gets freed,
|
||||
* the 2 regions would be combined, resulting in more free memory
|
||||
*/
|
||||
ptr2 = ptr + SIZEOF_STRUCT_MEM + size;
|
||||
ptr2 = (mem_size_t)(ptr + SIZEOF_STRUCT_MEM + size);
|
||||
/* create mem2 struct */
|
||||
mem2 = (struct mem *)(void *)&ram[ptr2];
|
||||
mem2->used = 0;
|
||||
|
@ -270,13 +270,15 @@ pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
|
||||
}
|
||||
case PBUF_RAM:
|
||||
{
|
||||
mem_size_t alloc_len = LWIP_MEM_ALIGN_SIZE(SIZEOF_STRUCT_PBUF + offset) + LWIP_MEM_ALIGN_SIZE(length);
|
||||
|
||||
u16_t payload_len = (u16_t)(LWIP_MEM_ALIGN_SIZE(offset) + LWIP_MEM_ALIGN_SIZE(length));
|
||||
mem_size_t alloc_len = (mem_size_t)(LWIP_MEM_ALIGN_SIZE(SIZEOF_STRUCT_PBUF) + payload_len);
|
||||
|
||||
/* bug #50040: Check for integer overflow when calculating alloc_len */
|
||||
if (alloc_len < LWIP_MEM_ALIGN_SIZE(length)) {
|
||||
if ((payload_len < LWIP_MEM_ALIGN_SIZE(length)) ||
|
||||
(alloc_len < LWIP_MEM_ALIGN_SIZE(length))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* If pbuf is to be allocated in RAM, allocate memory for it. */
|
||||
p = (struct pbuf*)mem_malloc(alloc_len);
|
||||
if (p == NULL) {
|
||||
@ -1045,7 +1047,7 @@ void pbuf_split_64k(struct pbuf *p, struct pbuf **rest)
|
||||
|
||||
/* continue until the total length (summed up as u16_t) overflows */
|
||||
while ((r != NULL) && ((u16_t)(tot_len_front + r->len) > tot_len_front)) {
|
||||
tot_len_front += r->len;
|
||||
tot_len_front = (u16_t)(tot_len_front + r->len);
|
||||
i = r;
|
||||
r = r->next;
|
||||
}
|
||||
@ -1056,7 +1058,7 @@ void pbuf_split_64k(struct pbuf *p, struct pbuf **rest)
|
||||
if (r != NULL) {
|
||||
/* Update the tot_len field in the first part */
|
||||
for (i = p; i != NULL; i = i->next) {
|
||||
i->tot_len -= r->tot_len;
|
||||
i->tot_len = (u16_t)(i->tot_len - r->tot_len);
|
||||
LWIP_ASSERT("tot_len/len mismatch in last pbuf",
|
||||
(i->next != NULL) || (i->tot_len == i->len));
|
||||
}
|
||||
|
@ -70,7 +70,7 @@
|
||||
"The Dynamic and/or Private Ports are those from 49152 through 65535" */
|
||||
#define UDP_LOCAL_PORT_RANGE_START 0xc000
|
||||
#define UDP_LOCAL_PORT_RANGE_END 0xffff
|
||||
#define UDP_ENSURE_LOCAL_PORT_RANGE(port) ((u16_t)(((port) & ~UDP_LOCAL_PORT_RANGE_START) + UDP_LOCAL_PORT_RANGE_START))
|
||||
#define UDP_ENSURE_LOCAL_PORT_RANGE(port) ((u16_t)(((port) & (u16_t)~UDP_LOCAL_PORT_RANGE_START) + UDP_LOCAL_PORT_RANGE_START))
|
||||
#endif
|
||||
|
||||
/* last local UDP port */
|
||||
@ -1088,7 +1088,7 @@ udp_disconnect(struct udp_pcb *pcb)
|
||||
pcb->remote_port = 0;
|
||||
pcb->netif_idx = NETIF_NO_INDEX;
|
||||
/* mark PCB as unconnected */
|
||||
pcb->flags &= ~UDP_FLAGS_CONNECTED;
|
||||
udp_clear_flags(pcb, UDP_FLAGS_CONNECTED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -308,7 +308,7 @@ void stats_init(void);
|
||||
|
||||
#define STATS_INC(x) ++lwip_stats.x
|
||||
#define STATS_DEC(x) --lwip_stats.x
|
||||
#define STATS_INC_USED(x, y) do { lwip_stats.x.used += y; \
|
||||
#define STATS_INC_USED(x, y, type) do { lwip_stats.x.used = (type)(lwip_stats.x.used + y); \
|
||||
if (lwip_stats.x.max < lwip_stats.x.used) { \
|
||||
lwip_stats.x.max = lwip_stats.x.used; \
|
||||
} \
|
||||
@ -318,7 +318,7 @@ void stats_init(void);
|
||||
#define stats_init()
|
||||
#define STATS_INC(x)
|
||||
#define STATS_DEC(x)
|
||||
#define STATS_INC_USED(x)
|
||||
#define STATS_INC_USED(x, y, type)
|
||||
#endif /* LWIP_STATS */
|
||||
|
||||
#if TCP_STATS
|
||||
@ -388,8 +388,8 @@ void stats_init(void);
|
||||
#if MEM_STATS
|
||||
#define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y
|
||||
#define MEM_STATS_INC(x) STATS_INC(mem.x)
|
||||
#define MEM_STATS_INC_USED(x, y) STATS_INC_USED(mem, y)
|
||||
#define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x -= y
|
||||
#define MEM_STATS_INC_USED(x, y) STATS_INC_USED(mem, y, mem_size_t)
|
||||
#define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x = (mem_size_t)((lwip_stats.mem.x) - (y))
|
||||
#define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP")
|
||||
#else
|
||||
#define MEM_STATS_AVAIL(x, y)
|
||||
@ -412,7 +412,7 @@ void stats_init(void);
|
||||
#if SYS_STATS
|
||||
#define SYS_STATS_INC(x) STATS_INC(sys.x)
|
||||
#define SYS_STATS_DEC(x) STATS_DEC(sys.x)
|
||||
#define SYS_STATS_INC_USED(x) STATS_INC_USED(sys.x, 1)
|
||||
#define SYS_STATS_INC_USED(x) STATS_INC_USED(sys.x, 1, STAT_COUNTER)
|
||||
#define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys)
|
||||
#else
|
||||
#define SYS_STATS_INC(x)
|
||||
|
@ -155,6 +155,10 @@ err_t udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p,
|
||||
#define udp_flags(pcb) ((pcb)->flags)
|
||||
#define udp_setflags(pcb, f) ((pcb)->flags = (f))
|
||||
|
||||
#define udp_set_flags(pcb, set_flags) do { (pcb)->flags = (u8_t)((pcb)->flags | (set_flags)); } while(0)
|
||||
#define udp_clear_flags(pcb, clr_flags) do { (pcb)->flags = (u8_t)((pcb)->flags & ~(clr_flags)); } while(0)
|
||||
#define udp_is_flag_set(pcb, flag) (((pcb)->flags & (flag)) != 0)
|
||||
|
||||
/* The following functions are the lower layer interface to UDP. */
|
||||
void udp_input (struct pbuf *p, struct netif *inp);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user