From c3b5257c3cab0fb176312eedc80afa33f7636849 Mon Sep 17 00:00:00 2001 From: Craig Edwards Date: Thu, 12 Dec 2024 23:17:02 +0000 Subject: [PATCH] tidy up casting in decompression code --- include/dpp/discordclient.h | 2 +- src/dpp/discordclient.cpp | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/include/dpp/discordclient.h b/include/dpp/discordclient.h index 2b08949971..309119f197 100644 --- a/include/dpp/discordclient.h +++ b/include/dpp/discordclient.h @@ -309,7 +309,7 @@ class DPP_EXPORT discord_client : public websocket_client * a vector of length zero, but when compression is * enabled it will be resized to a DECOMP_BUFFER_SIZE buffer. */ - std::vector decomp_buffer; + std::vector decomp_buffer; /** * @brief Decompressed string diff --git a/src/dpp/discordclient.cpp b/src/dpp/discordclient.cpp index f232f0c278..d06a5ba2d1 100644 --- a/src/dpp/discordclient.cpp +++ b/src/dpp/discordclient.cpp @@ -190,7 +190,7 @@ void discord_client::run() bool discord_client::handle_frame(const std::string &buffer, ws_opcode opcode) { - auto& data = (std::string&)buffer; + auto& data = const_cast(buffer); /* gzip compression is a special case */ if (compressed) { @@ -202,7 +202,7 @@ bool discord_client::handle_frame(const std::string &buffer, ws_opcode opcode) zlib->d_stream.next_in = (Bytef*)buffer.data(); zlib->d_stream.avail_in = static_cast(buffer.size()); do { - zlib->d_stream.next_out = reinterpret_cast(decomp_buffer.data()); + zlib->d_stream.next_out = static_cast(decomp_buffer.data()); zlib->d_stream.avail_out = DECOMP_BUFFER_SIZE; int ret = inflate(&(zlib->d_stream), Z_NO_FLUSH); size_t have = DECOMP_BUFFER_SIZE - zlib->d_stream.avail_out; @@ -213,21 +213,18 @@ bool discord_client::handle_frame(const std::string &buffer, ws_opcode opcode) this->error(err_compression_stream); this->close(); return false; - return true; case Z_DATA_ERROR: this->error(err_compression_data); this->close(); return false; - return true; case Z_MEM_ERROR: this->error(err_compression_memory); this->close(); return false; - return true; case Z_OK: - this->decompressed.append((const char*)decomp_buffer.data(), have); + this->decompressed.append(decomp_buffer.begin(), decomp_buffer.begin() + have); this->decompressed_total += have; - break; + break; default: /* Stub */ break;