@@ -5121,7 +5121,7 @@ static void rx_ip(struct mg_tcpip_if *ifp, struct pkt *pkt) {
5121
5121
if ((pkt->ip->ver >> 4) != 4) return; // Not IP
5122
5122
ihl = pkt->ip->ver & 0x0F;
5123
5123
if (ihl < 5) return; // bad IHL
5124
- if (pkt->pay.len < (ihl * 4)) return; // Truncated / malformed
5124
+ if (pkt->pay.len < (uint16_t)( ihl * 4)) return; // Truncated / malformed
5125
5125
// There can be link padding, take length from IP header
5126
5126
len = mg_ntohs(pkt->ip->len); // IP datagram length
5127
5127
if (len < (ihl * 4) || len > pkt->pay.len) return; // malformed
@@ -5166,7 +5166,7 @@ static void rx_ip(struct mg_tcpip_if *ifp, struct pkt *pkt) {
5166
5166
pkt->tcp = (struct tcp *) (pkt->pay.buf);
5167
5167
if (pkt->pay.len < sizeof(*pkt->tcp)) return;
5168
5168
off = pkt->tcp->off >> 4; // account for opts
5169
- if (pkt->pay.len < (4 * off)) return;
5169
+ if (pkt->pay.len < (uint16_t)( 4 * off)) return;
5170
5170
mkpay(pkt, (uint32_t *) pkt->tcp + off);
5171
5171
MG_VERBOSE(("TCP %M:%hu -> %M:%hu len %u", mg_print_ip4, &pkt->ip->src,
5172
5172
mg_ntohs(pkt->tcp->sport), mg_print_ip4, &pkt->ip->dst,
@@ -7811,26 +7811,19 @@ bool mg_ota_end(void) {
7811
7811
7812
7812
7813
7813
7814
- size_t mg_queue_vprintf(struct mg_queue *q, const char *fmt, va_list *ap) {
7815
- va_list ap_copy;
7816
- va_copy(ap_copy, *ap);
7817
- size_t len = mg_vsnprintf(NULL, 0, fmt, &ap_copy);
7818
- char *buf;
7819
- if (len == 0 || mg_queue_book(q, &buf, len + 1) < len + 1) {
7820
- len = 0; // Nah. Not enough space
7821
- } else {
7822
- len = mg_vsnprintf((char *) buf, len + 1, fmt, ap);
7823
- mg_queue_add(q, len);
7824
- }
7825
- return len;
7826
- }
7827
-
7828
7814
size_t mg_queue_printf(struct mg_queue *q, const char *fmt, ...) {
7829
- va_list ap ;
7815
+ char *buf ;
7830
7816
size_t len;
7831
- va_start(ap, fmt);
7832
- len = mg_queue_vprintf(q, fmt, &ap);
7833
- va_end(ap);
7817
+ va_list ap1, ap2;
7818
+ va_start(ap1, fmt);
7819
+ len = mg_vsnprintf(NULL, 0, fmt, &ap1);
7820
+ va_end(ap1);
7821
+ if (len == 0 || mg_queue_book(q, &buf, len + 1) < len + 1)
7822
+ return 0; // Nah. Not enough space
7823
+ va_start(ap2, fmt);
7824
+ len = mg_vsnprintf(buf, len + 1, fmt, &ap2);
7825
+ mg_queue_add(q, len);
7826
+ va_end(ap2);
7834
7827
return len;
7835
7828
}
7836
7829
0 commit comments