{"action":"opened","issue":{"url":"https://api.github.com/repos/arvidn/libtorrent/issues/634","repository_url":"https://api.github.com/repos/arvidn/libtorrent","labels_url":"https://api.github.com/repos/arvidn/libtorrent/issues/634/labels{/name}","comments_url":"https://api.github.com/repos/arvidn/libtorrent/issues/634/comments","events_url":"https://api.github.com/repos/arvidn/libtorrent/issues/634/events","html_url":"https://github.com/arvidn/libtorrent/issues/634","id":149971803,"number":634,"title":"utp_socket_impl::write_payload assert","user":{"login":"ajax16384","id":340593,"avatar_url":"https://avatars.githubusercontent.com/u/340593?v=3","gravatar_id":"","url":"https://api.github.com/users/ajax16384","html_url":"https://github.com/ajax16384","followers_url":"https://api.github.com/users/ajax16384/followers","following_url":"https://api.github.com/users/ajax16384/following{/other_user}","gists_url":"https://api.github.com/users/ajax16384/gists{/gist_id}","starred_url":"https://api.github.com/users/ajax16384/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajax16384/subscriptions","organizations_url":"https://api.github.com/users/ajax16384/orgs","repos_url":"https://api.github.com/users/ajax16384/repos","events_url":"https://api.github.com/users/ajax16384/events{/privacy}","received_events_url":"https://api.github.com/users/ajax16384/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-21T05:35:35Z","updated_at":"2016-04-21T05:35:35Z","closed_at":null,"body":"master debug build raise assert\r\n````c++\r\n\tm_write_buffer.size == 0 , size == -1 //!!!\r\n \tTORRENT_ASSERT(!m_write_buffer.empty() || size == 0);\r\n \tlibtorrent::utp_socket_impl::write_payload(unsigned char * ptr, int size) Line 1637\tC++\r\n>\tlibtorrent::utp_socket_impl::send_pkt(int flags) Line 1943\tC++\r\n \tlibtorrent::utp_socket_impl::incoming_packet(const unsigned char * buf, int size, const boost::asio::ip::basic_endpoint<boost::asio::ip::udp> & ep, std::chrono::time_point<std::chrono::steady_clock,std::chrono::duration<__int64,std::ratio<1,1000000000> > > receive_time) Line 3191\tC++\r\n \tlibtorrent::utp_incoming_packet(libtorrent::utp_socket_impl * s, const char * p, int size, const boost::asio::ip::basic_endpoint<boost::asio::ip::udp> & ep, std::chrono::time_point<std::chrono::steady_clock,std::chrono::duration<__int64,std::ratio<1,1000000000> > > receive_time) Line 756\tC++\r\n \tlibtorrent::utp_socket_manager::incoming_packet(const boost::system::error_code & ec, const boost::asio::ip::basic_endpoint<boost::asio::ip::udp> & ep, const char * p, int size) Line 268\tC++\r\n \tlibtorrent::udp_socket::call_handler(const boost::system::error_code & ec, const boost::asio::ip::basic_endpoint<boost::asio::ip::udp> & ep, const char * buf, int size) Line 363\tC++\r\n \tlibtorrent::udp_socket::on_read_impl(const boost::asio::ip::basic_endpoint<boost::asio::ip::udp> & ep, const boost::system::error_code & e, unsigned int bytes_transferred) Line 519\tC++\r\n \tlibtorrent::udp_socket::on_read(const boost::system::error_code & ec, boost::asio::basic_datagram_socket<boost::asio::ip::udp,boost::asio::datagram_socket_service<boost::asio::ip::udp> > * s) Line 342\tC++\r\n````\r\n\r\ncaller method has following values\r\n\r\n````c++\r\n    int const effective_mtu = mtu_probe ? m_mtu : m_mtu_floor; //  m_mtu == 29, m_mtu_floor == 29\r\n    int payload_size = (std::min)(m_write_buffer_size, effective_mtu - header_size); // m_write_buffer_size == 0, effective_mtu == 29, header_size == 30, payload_size==-1 !!!\r\n````\r\nso the possible workaround may be:\r\n````c++\r\n-int payload_size = (std::min)(m_write_buffer_size, effective_mtu - header_size);\r\n+int payload_size = (std::max)(0, (std::min)(m_write_buffer_size , effective_mtu - header_size));\r\n````"}}