Skip to content

Commit 908381e

Browse files
committed
examples: fix FRONTPAGE length off-by-one error
1 parent 3db8159 commit 908381e

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

examples/AsyncCam/handlers.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ rewriteFrontpage(const esp32cam::Settings& s, const String& var) {
149149

150150
static void
151151
handleFrontpage(AsyncWebServerRequest* req) {
152+
static const size_t contentLength = strlen(FRONTPAGE);
152153
auto settings = esp32cam::Camera.status();
153-
req->send(200, "text/html", reinterpret_cast<const uint8_t*>(FRONTPAGE), sizeof(FRONTPAGE),
154+
req->send(200, "text/html", reinterpret_cast<const uint8_t*>(FRONTPAGE), contentLength,
154155
[=](const String& var) { return rewriteFrontpage(settings, var); });
155156
}
156157

examples/WifiCam/handlers.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ serveMjpeg() {
7878
void
7979
addRequestHandlers() {
8080
server.on("/", HTTP_GET, [] {
81-
server.setContentLength(sizeof(FRONTPAGE));
81+
static const size_t contentLength = strlen(FRONTPAGE);
82+
server.setContentLength(contentLength);
8283
server.send(200, "text/html");
83-
server.sendContent(FRONTPAGE, sizeof(FRONTPAGE));
84+
server.sendContent(FRONTPAGE, contentLength);
8485
});
8586

8687
server.on("/robots.txt", HTTP_GET,

0 commit comments

Comments
 (0)