Skip to content

Commit a9e31a7

Browse files
committed
Fix empty returns in non-void functions
- Previously lwIP_ASSERT expanded to `return;`, which breaks when used inside functions with non-void return types (causing -Werror failures): this patch updates the macro to allow specifying an appropriate return value. - nodemcu_mdns.c: `send_packet`, also had empty returns. While these could be bypassed with `-Wno-error=return-type`, explicitly returning a value is safer and more correct.
1 parent a5e48e5 commit a9e31a7

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

app/lwip/app/espconn_buf.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__;
2020
#define lwIP_unlikely(Expression) !!(Expression)
2121
#endif
2222

23-
#define lwIP_ASSERT(Expression) do{if(!(Expression)) {os_printf("%s %d\n", __func__, __LINE__);return;}}while(0)
23+
#define lwIP_ASSERT(Expression) \
24+
do { if(!(Expression)) { os_printf("%s %d\n", __func__, __LINE__); return; }} while(0)
25+
26+
#define lwIP_ASSERT_RET(Expression, Retval) \
27+
do { if(!(Expression)) { os_printf("%s %d\n", __func__, __LINE__); return (Retval); }} while(0)
2428

2529
ringbuf_t ringbuf_new(size_t capacity)
2630
{
@@ -101,7 +105,7 @@ const void* ringbuf_head(const struct ringbuf_t *rb)
101105

102106
static uint8_t *ringbuf_nextp(ringbuf_t rb, const uint8_t *p)
103107
{
104-
lwIP_ASSERT((p >= rb->buf) && (p < ringbuf_end(rb)));
108+
lwIP_ASSERT_RET((p >= rb->buf) && (p < ringbuf_end(rb)), 0);
105109
return rb->buf + ((++p -rb->buf) % ringbuf_buffer_size(rb));
106110
}
107111

@@ -113,7 +117,7 @@ size_t ringbuf_findchr(const struct ringbuf_t *rb, int c, size_t offset)
113117
return bytes_used;
114118

115119
const uint8_t *start = rb ->buf + (((rb->tail - rb->buf) + offset) % ringbuf_buffer_size(rb));
116-
lwIP_ASSERT(bufend > start);
120+
lwIP_ASSERT_RET(bufend > start, 0);
117121
size_t n = LWIP_MIN(bufend - start, bytes_used - offset);
118122
const uint8_t *found = (const uint8_t *)memchr(start, c, n);
119123
if (found)
@@ -131,7 +135,7 @@ size_t ringbuf_memset(ringbuf_t dst, int c, size_t len)
131135

132136
while (nwritten != count){
133137

134-
lwIP_ASSERT(bufend > dst->head);
138+
lwIP_ASSERT_RET(bufend > dst->head, 0);
135139
size_t n = LWIP_MIN(bufend - dst->head, count - nwritten);
136140
os_memset(dst->head, c, n);
137141
dst->head += n;
@@ -143,7 +147,7 @@ size_t ringbuf_memset(ringbuf_t dst, int c, size_t len)
143147

144148
if (overflow){
145149
dst->tail = ringbuf_nextp(dst, dst->head);
146-
lwIP_ASSERT(ringbuf_is_full(dst));
150+
lwIP_ASSERT_RET(ringbuf_is_full(dst), 0);
147151
}
148152

149153
return nwritten;
@@ -157,7 +161,7 @@ void *ringbuf_memcpy_into(ringbuf_t dst,const void *src, size_t count)
157161
size_t nread = 0;
158162

159163
while (nread != count){
160-
lwIP_ASSERT(bufend > dst->head);
164+
lwIP_ASSERT_RET(bufend > dst->head, NULL);
161165
size_t n = LWIP_MIN(bufend - dst->head, count - nread);
162166
os_memcpy(dst->head, u8src + nread, n);
163167
dst->head += n;
@@ -169,7 +173,7 @@ void *ringbuf_memcpy_into(ringbuf_t dst,const void *src, size_t count)
169173

170174
if (overflow) {
171175
dst->tail = ringbuf_nextp(dst, dst->head);
172-
lwIP_ASSERT(ringbuf_is_full(dst));
176+
lwIP_ASSERT_RET(ringbuf_is_full(dst), NULL);
173177
}
174178

175179
return dst->head;
@@ -187,7 +191,7 @@ void *ringbuf_memcpy_from(void *dst,ringbuf_t src, size_t count)
187191
size_t nwritten = 0;
188192

189193
while (nwritten != count){
190-
lwIP_ASSERT(bufend > src->tail);
194+
lwIP_ASSERT_RET(bufend > src->tail, NULL);
191195
size_t n = LWIP_MIN(bufend - src->tail, count - nwritten);
192196
os_memcpy((uint8_t*)u8dst + nwritten, src->tail, n);
193197
src->tail += n;
@@ -197,7 +201,7 @@ void *ringbuf_memcpy_from(void *dst,ringbuf_t src, size_t count)
197201
src->tail = src->buf;
198202
}
199203

200-
lwIP_ASSERT(count + ringbuf_bytes_used(src) == bytes_used);
204+
lwIP_ASSERT_RET(count + ringbuf_bytes_used(src) == bytes_used, NULL);
201205
return src->tail;
202206
}
203207

app/net/nodemcu_mdns.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,16 +317,16 @@ static err_t send_packet(struct pbuf *p, struct ip_addr *dst_addr, u16_t dst_por
317317
if (addr_ptr) {
318318
if (wifi_get_opmode() == 0x02) {
319319
if (!ap_netif) {
320-
return;
320+
return 0;
321321
}
322322
memcpy(addr_ptr, &ap_netif->ip_addr, sizeof(ap_netif->ip_addr));
323323
} else {
324324
if (!sta_netif) {
325-
return;
325+
return 0;
326326
}
327327
memcpy(addr_ptr, &sta_netif->ip_addr, sizeof(sta_netif->ip_addr));
328328
}
329-
}
329+
}
330330

331331
if (dst_addr) {
332332
err = udp_sendto(mdns_pcb, p, dst_addr, dst_port);

0 commit comments

Comments
 (0)