Last active
December 18, 2018 05:55
-
-
Save fuzz-ai/bd945c32265641b4981c560f90dcca2a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int buf_size = MAX_MESSAGE_SIZE + 1024; | |
| char buf[buf_size]; | |
| int main( int argc, char *argv[] ) { | |
| std::cin.read( buf, buf_size ); | |
| if ( !std::cin.eof() ) { | |
| std::cout << "String too long.\n"; | |
| return 1; | |
| } | |
| size_t size = std::cin.gcount(); | |
| try { | |
| message m; | |
| // Message size and type will be filled in so that they match how | |
| // many bytes we actually filled, and so that the type matches the | |
| // decode function we're trying to use. | |
| // | |
| // m.size does *not* include the header, according to the original code.. | |
| // | |
| // Data is padded on the wire but shortened to m.size before | |
| // demarshaling. | |
| m.size = fc::min( size, (size_t)MAX_MESSAGE_SIZE ); | |
| m.data.resize( m.size ); | |
| std::copy( buf, buf + m.size, m.data.begin() ); | |
| m.msg_type = graphene::net::hello_message_type; | |
| graphene::net::hello_message hello = m.as<graphene::net::hello_message>(); | |
| } catch ( fc::exception &e ) { | |
| std::cout << e.to_string() << "\n"; | |
| return 1; | |
| } catch ( std::bad_alloc &e ) { | |
| std::cout << "Out of memory!"; | |
| abort(); | |
| } | |
| return 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment