From e2e42ac65cd37a4f757b3d5c2b5d4e421a50a150 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 30 Jun 2021 15:40:57 +0200 Subject: [PATCH] Patch httplib.h for gcc `maybe-uninitialized` warning. Recent version of gcc warn about the use `buf` where it may be uninitialized. But here, buf is used as a output buffer to initialize it. I'm not sure we can fix this differently than ignoring the warning. --- test/httplib.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/test/httplib.h b/test/httplib.h index d9611df35..576936d69 100644 --- a/test/httplib.h +++ b/test/httplib.h @@ -2890,12 +2890,15 @@ inline ssize_t Stream::write(const std::string &s) { template inline ssize_t Stream::write_format(const char *fmt, const Args &... args) { std::array buf; - +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunknown-warning-option" +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #if defined(_MSC_VER) && _MSC_VER < 1900 auto sn = _snprintf_s(buf, bufsiz, buf.size() - 1, fmt, args...); #else auto sn = snprintf(buf.data(), buf.size() - 1, fmt, args...); #endif +#pragma GCC diagnostic pop if (sn <= 0) { return sn; } auto n = static_cast(sn); @@ -3651,7 +3654,11 @@ Server::process_request(Stream &strm, bool last_connection, const std::function &setup_request) { std::array buf{}; - detail::stream_line_reader line_reader(strm, buf.data(), buf.size()); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunknown-warning-option" +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" + detail::stream_line_reader line_reader(strm, buf.data(), buf.size()); +#pragma GCC diagnostic pop // Connection has been closed on client if (!line_reader.getline()) { return false; } @@ -3757,9 +3764,11 @@ inline socket_t Client::create_client_socket() const { inline bool Client::read_response_line(Stream &strm, Response &res) { std::array buf; - +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunknown-warning-option" +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" detail::stream_line_reader line_reader(strm, buf.data(), buf.size()); - +#pragma GCC diagnostic pop if (!line_reader.getline()) { return false; } const static std::regex re("(HTTP/1\\.[01]) (\\d+?) .*\r\n");