Use fixed stack buffer for query strings bounded by CONFIG_HTTPD_MAX_URI_LEN

Query strings cannot exceed the max URI length, so SmallBufferWithHeapFallback
is unnecessary. Use a plain stack array instead for zero heap allocation.
This commit is contained in:
J. Nick Koston
2026-02-11 18:38:25 -06:00
parent 92d800412a
commit 53345724f2
2 changed files with 7 additions and 10 deletions
+4 -7
View File
@@ -1,5 +1,4 @@
#ifdef USE_ESP32
#include <memory>
#include <cstring>
#include <cctype>
#include "esphome/core/helpers.h"
@@ -56,15 +55,13 @@ optional<std::string> query_key_value(const char *query_url, size_t query_len, c
return {};
}
// Use stack buffer for typical query strings, heap fallback for large ones
SmallBufferWithHeapFallback<256, char> val(query_len);
if (httpd_query_key_value(query_url, key, val.get(), query_len) != ESP_OK) {
char val[CONFIG_HTTPD_MAX_URI_LEN + 1];
if (httpd_query_key_value(query_url, key, val, query_len) != ESP_OK) {
return {};
}
url_decode(val.get());
return {val.get()};
url_decode(val);
return {val};
}
bool query_has_key(const char *query_url, size_t query_len, const char *key) {
@@ -422,11 +422,11 @@ static auto search_query_sources(httpd_req_t *req, const std::string &post_query
if (len == 0) {
return {};
}
SmallBufferWithHeapFallback<256, char> buf(len + 1);
if (httpd_req_get_url_query_str(req, buf.get(), len + 1) != ESP_OK) {
char buf[AsyncWebServerRequest::URL_BUF_SIZE];
if (httpd_req_get_url_query_str(req, buf, len + 1) != ESP_OK) {
return {};
}
return func(buf.get(), len, name);
return func(buf, len, name);
}
optional<std::string> AsyncWebServerRequest::find_query_value_(const char *name) const {