@@ -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
2529ringbuf_t ringbuf_new (size_t capacity )
2630{
@@ -101,7 +105,7 @@ const void* ringbuf_head(const struct ringbuf_t *rb)
101105
102106static 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
0 commit comments