Set length macro for pbuf
/* Set size of pbuf structure */
#define SIZEOF_PBUF_STRUCT ESP_MEM_ALIGN(sizeof(esp_pbuf_t))
+#define SET_NEW_LEN(v, len) do { if ((v) != NULL) { *(v) = (len); } } while (0)
/**
* \brief Skip pbufs for desired offset
@@ -441,24 +442,20 @@ esp_pbuf_strcmp(const esp_pbuf_p pbuf, const char* str, size_t offset) {
const void *
esp_pbuf_get_linear_addr(const esp_pbuf_p pbuf, size_t offset, size_t* new_len) {
esp_pbuf_p p = pbuf;
+
if (pbuf == NULL || pbuf->tot_len < offset) { /* Check input parameters */
- if (new_len != NULL) {
- *new_len = 0;
- }
+ SET_NEW_LEN(new_len, 0);
return NULL;
}
if (offset) { /* Is there any offset? */
p = pbuf_skip(pbuf, offset, &offset); /* Skip pbuf to desired length */
if (p == NULL) {
- if (new_len != NULL) {
- *new_len = 0;
- }
+ SET_NEW_LEN(new_len, 0);
return NULL;
}
}
- if (new_len != NULL) {
- *new_len = p->len - offset; /* Save memory length user can use */
- }
+
+ SET_NEW_LEN(new_len, p->len - offset);
return &p->payload[offset]; /* Return memory at desired offset */
}
