Skip to content

Commit

Permalink
tidy up casting in decompression code
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed Dec 12, 2024
1 parent ae0565c commit c3b5257
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/dpp/discordclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char*> decomp_buffer;
std::vector<unsigned char> decomp_buffer;

/**
* @brief Decompressed string
Expand Down
11 changes: 4 additions & 7 deletions src/dpp/discordclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string&>(buffer);

/* gzip compression is a special case */
if (compressed) {
Expand All @@ -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<uInt>(buffer.size());
do {
zlib->d_stream.next_out = reinterpret_cast<Bytef*>(decomp_buffer.data());
zlib->d_stream.next_out = static_cast<Bytef*>(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;
Expand All @@ -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;
Expand Down

0 comments on commit c3b5257

Please sign in to comment.