From 4a47cf803c0f38b387fb7558f596be5f580ba307 Mon Sep 17 00:00:00 2001 From: "hrushikesh.bhosale" Date: Wed, 26 Feb 2025 14:48:40 +0530 Subject: [PATCH] feat(esp_http_server/httpd_parse): Cosmetic changes in httpd_parse.c Removed the unused variable buf_len --- components/esp_http_server/src/httpd_parse.c | 21 ++++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/components/esp_http_server/src/httpd_parse.c b/components/esp_http_server/src/httpd_parse.c index a0388c5848..ffce454fba 100644 --- a/components/esp_http_server/src/httpd_parse.c +++ b/components/esp_http_server/src/httpd_parse.c @@ -895,13 +895,13 @@ esp_err_t httpd_query_key_value(const char *qry_str, const char *key, char *val, /* Copy value to the caller's buffer. */ size_t copy_len = MIN(val_len, val_size - 1); - memcpy(val, val_ptr, copy_len); - val[copy_len] = '\0'; - /* If buffer length is smaller than needed, return truncation error */ if (copy_len < val_len) { return ESP_ERR_HTTPD_RESULT_TRUNC; } + memcpy(val, val_ptr, copy_len); + val[copy_len] = '\0'; + return ESP_OK; } ESP_LOGD(TAG, LOG_FMT("key %s not found"), key); @@ -960,12 +960,12 @@ esp_err_t httpd_req_get_url_query_str(httpd_req_t *r, char *buf, size_t buf_len) /* Copy data to the caller's buffer. */ size_t copy_len = MIN(data_len, buf_len - 1); - memcpy(buf, qry, copy_len); - buf[copy_len] = '\0'; - if (copy_len < data_len) { return ESP_ERR_HTTPD_RESULT_TRUNC; } + memcpy(buf, qry, copy_len); + buf[copy_len] = '\0'; + return ESP_OK; } return ESP_ERR_NOT_FOUND; @@ -1040,7 +1040,6 @@ esp_err_t httpd_req_get_hdr_value_str(httpd_req_t *r, const char *field, char *v struct httpd_req_aux *ra = r->aux; const char *hdr_ptr = ra->scratch; /*!< Request headers are kept in scratch buffer */ unsigned count = ra->req_hdrs_count; /*!< Count set during parsing */ - const size_t buf_len = val_size; while (count--) { /* Search for the ':' character. Else, it would mean @@ -1137,16 +1136,16 @@ esp_err_t static httpd_cookie_key_value(const char *cookie_str, const char *key, /* Copy value to the caller's buffer. */ size_t copy_len = MIN(val_len, *val_size - 1); + /* If buffer length is smaller than needed, return truncation error */ + if (copy_len < val_len) { + return ESP_ERR_HTTPD_RESULT_TRUNC; + } memcpy(val, val_ptr, copy_len); val[copy_len] = '\0'; /* Save actual Cookie value size (including terminating null) */ *val_size = copy_len + 1; - /* If buffer length is smaller than needed, return truncation error */ - if (copy_len < val_len) { - return ESP_ERR_HTTPD_RESULT_TRUNC; - } return ESP_OK; } ESP_LOGD(TAG, LOG_FMT("cookie %s not found"), key);