Skip to content

Commit

Permalink
Fixed uninitialized c-arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
COM8 committed Jan 3, 2024
1 parent 5191512 commit eec4b44
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions test/httpServer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "httpServer.hpp"
#include <array>
#include <chrono>
#include <string>
#include <system_error>
Expand Down Expand Up @@ -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<char, 100> x{0};
std::array<char, 100> 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{
Expand All @@ -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"
"}"};
}
Expand Down Expand Up @@ -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<char, 100> x{0};
std::array<char, 100> 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()) {
Expand All @@ -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"
"}"};
}
Expand Down Expand Up @@ -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<char, 100> x{0};
std::array<char, 100> 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()) {
Expand All @@ -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"
"}"};
}
Expand Down

0 comments on commit eec4b44

Please sign in to comment.