Skip to content

Commit

Permalink
Replace dynamic-length raw char array with vector
Browse files Browse the repository at this point in the history
  • Loading branch information
abitmore committed Mar 24, 2021
1 parent 78815cb commit 0aa3831
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions libraries/net/message_oriented_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,18 @@ namespace graphene { namespace net {
elog("Trying to send a message larger than MAX_MESSAGE_SIZE. This probably won't work...");
//pad the message we send to a multiple of 16 bytes
size_t size_with_padding = 16 * ((size_of_message_and_header + 15) / 16);
std::unique_ptr<char[]> padded_message( std::make_unique<char[]>(size_with_padding) );
std::vector<char> padded_message( size_with_padding );

memcpy(padded_message.get(), (char*)&message_to_send, sizeof(message_header));
memcpy(padded_message.get() + sizeof(message_header), message_to_send.data.data(), message_to_send.size.value() );
char* padding_space = padded_message.get() + sizeof(message_header) + message_to_send.size.value();
memcpy( padded_message.data(), (const char*)&message_to_send, sizeof(message_header) );
memcpy( padded_message.data() + sizeof(message_header), message_to_send.data.data(),
message_to_send.size.value() );
char* padding_space = padded_message.data() + sizeof(message_header) + message_to_send.size.value();
memset(padding_space, 0, size_with_padding - size_of_message_and_header);
_sock.write(padded_message.get(), size_with_padding);
_sock.write( padded_message.data(), size_with_padding );
_sock.flush();
_bytes_sent += size_with_padding;
_last_message_sent_time = fc::time_point::now();
} FC_RETHROW_EXCEPTIONS( warn, "unable to send message" );
} FC_RETHROW_EXCEPTIONS( warn, "unable to send message" )
}

void message_oriented_connection_impl::close_connection()
Expand Down

0 comments on commit 0aa3831

Please sign in to comment.