From d547d8d2c30a7d00852855da8ecc15c0cc424b0e Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Sat, 16 Mar 2024 18:04:41 -0700 Subject: Check optionals in tidy clang-tidy-18 makes this feature stable enough for us to use in general. Enable the check, and fix the couple of regressions that have snuck in since we last ran the check. Tidy seems to not be able to understand that ASSERT will not continue, so if we ASSERT a std::optional, it's not a bug. Add explicit checks to keep tidy happy. Tested: clang-tidy passes. Change-Id: I0986453851da5471056a7b47b8ad57a9801df259 Signed-off-by: Ed Tanous --- http/http2_connection.hpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'http') diff --git a/http/http2_connection.hpp b/http/http2_connection.hpp index 749ac282ef..4b1b2dcb91 100644 --- a/http/http2_connection.hpp +++ b/http/http2_connection.hpp @@ -104,7 +104,10 @@ class HTTP2Connection : } Http2StreamData& stream = streamIt->second; BMCWEB_LOG_DEBUG("File read callback length: {}", length); - + if (!stream.writer) + { + return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; + } boost::beast::error_code ec; boost::optional> out = stream.writer->getWithMaxSize(ec, length); @@ -230,10 +233,11 @@ class HTTP2Connection : close(); return -1; } - if (it->second.reqReader) + auto& reqReader = it->second.reqReader; + if (reqReader) { boost::beast::error_code ec; - it->second.reqReader->finish(ec); + reqReader->finish(ec); if (ec) { BMCWEB_LOG_CRITICAL("Failed to finalize payload"); @@ -289,15 +293,17 @@ class HTTP2Connection : close(); return -1; } - if (!thisStream->second.reqReader) + + std::optional& reqReader = + thisStream->second.reqReader; + if (!reqReader) { - thisStream->second.reqReader.emplace( - thisStream->second.req.req.base(), - thisStream->second.req.req.body()); + BMCWEB_LOG_ERROR("No reader init {}", streamId); + close(); + return -1; } boost::beast::error_code ec; - thisStream->second.reqReader->put(boost::asio::const_buffer(data, len), - ec); + reqReader->put(boost::asio::const_buffer(data, len), ec); if (ec) { BMCWEB_LOG_CRITICAL("Failed to write payload"); -- cgit v1.2.3