From eec4b441e83527e5182d8d0c006bd484a614faba Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Wed, 3 Jan 2024 16:51:40 +0100 Subject: [PATCH 1/2] Fixed uninitialized c-arrays --- test/httpServer.cpp | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/test/httpServer.cpp b/test/httpServer.cpp index 9514de51f..bc8359415 100644 --- a/test/httpServer.cpp +++ b/test/httpServer.cpp @@ -1,4 +1,5 @@ #include "httpServer.hpp" +#include #include #include #include @@ -394,12 +395,12 @@ void HttpServer::OnRequestUrlPost(mg_connection* conn, mg_http_message* msg) { std::string headers = "Content-Type: application/json\r\n"; - char x[100]; - char y[100]; - mg_http_get_var(&(msg->body), "x", x, sizeof(x)); - mg_http_get_var(&(msg->body), "y", y, sizeof(y)); - std::string x_string{x}; - std::string y_string{y}; + std::array x{0}; + std::array y{0}; + mg_http_get_var(&(msg->body), "x", x.data(), x.size()); + mg_http_get_var(&(msg->body), "y", y.data(), y.size()); + std::string x_string{x.data()}; + std::string y_string{y.data()}; std::string response; if (y_string.empty()) { response = std::string{ @@ -418,7 +419,7 @@ void HttpServer::OnRequestUrlPost(mg_connection* conn, mg_http_message* msg) { y_string + ",\n" " \"sum\": " + - std::to_string(atoi(x) + atoi(y)) + + std::to_string(atoi(x.data()) + atoi(y.data())) + "\n" "}"}; } @@ -519,12 +520,12 @@ void HttpServer::OnRequestDeleteNotAllowed(mg_connection* conn, mg_http_message* void HttpServer::OnRequestPut(mg_connection* conn, mg_http_message* msg) { if (std::string{msg->method.ptr, msg->method.len} == std::string{"PUT"}) { - char x[100]; - char y[100]; - mg_http_get_var(&(msg->body), "x", x, sizeof(x)); - mg_http_get_var(&(msg->body), "y", y, sizeof(y)); - std::string x_string = std::string{x}; - std::string y_string = std::string{y}; + std::array x{0}; + std::array y{0}; + mg_http_get_var(&(msg->body), "x", x.data(), x.size()); + mg_http_get_var(&(msg->body), "y", y.data(), y.size()); + std::string x_string{x.data()}; + std::string y_string{y.data()}; std::string headers = "Content-Type: application/json\r\n"; std::string response; if (y_string.empty()) { @@ -544,7 +545,7 @@ void HttpServer::OnRequestPut(mg_connection* conn, mg_http_message* msg) { y_string + ",\n" " \"sum\": " + - std::to_string(atoi(x) + atoi(y)) + + std::to_string(atoi(x.data()) + atoi(y.data())) + "\n" "}"}; } @@ -591,12 +592,12 @@ void HttpServer::OnRequestPutNotAllowed(mg_connection* conn, mg_http_message* ms void HttpServer::OnRequestPatch(mg_connection* conn, mg_http_message* msg) { if (std::string{msg->method.ptr, msg->method.len} == std::string{"PATCH"}) { - char x[100]; - char y[100]; - mg_http_get_var(&(msg->body), "x", x, sizeof(x)); - mg_http_get_var(&(msg->body), "y", y, sizeof(y)); - std::string x_string = std::string{x}; - std::string y_string = std::string{y}; + std::array x{0}; + std::array y{0}; + mg_http_get_var(&(msg->body), "x", x.data(), x.size()); + mg_http_get_var(&(msg->body), "y", y.data(), y.size()); + std::string x_string{x.data()}; + std::string y_string{y.data()}; std::string headers = "Content-Type: application/json\r\n"; std::string response; if (y_string.empty()) { @@ -616,7 +617,7 @@ void HttpServer::OnRequestPatch(mg_connection* conn, mg_http_message* msg) { y_string + ",\n" " \"sum\": " + - std::to_string(atoi(x) + atoi(y)) + + std::to_string(atoi(x.data()) + atoi(y.data())) + "\n" "}"}; } From 36409bcb3e207955621fb6b2295d296052a68bc2 Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Wed, 3 Jan 2024 17:28:42 +0100 Subject: [PATCH 2/2] Reduced the number of requests inside AsyncGetMultipleReflectTest This is to get around connection failures inside mongoose when there are too many parallel requests. --- test/session_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/session_tests.cpp b/test/session_tests.cpp index 23b5b7816..2ce714687 100644 --- a/test/session_tests.cpp +++ b/test/session_tests.cpp @@ -1361,7 +1361,7 @@ TEST(AsyncRequestsTests, AsyncGetMultipleTemporarySessionTest) { TEST(AsyncRequestsTests, AsyncGetMultipleReflectTest) { Url url{server->GetBaseUrl() + "/hello.html"}; std::vector responses; - for (size_t i = 0; i < 100; ++i) { + for (size_t i = 0; i < 10; ++i) { std::shared_ptr session = std::make_shared(); session->SetUrl(url); session->SetParameters({{"key", std::to_string(i)}});