{"action":"created","issue":{"url":"https://api.github.com/repos/arvidn/libtorrent/issues/41","labels_url":"https://api.github.com/repos/arvidn/libtorrent/issues/41/labels{/name}","comments_url":"https://api.github.com/repos/arvidn/libtorrent/issues/41/comments","events_url":"https://api.github.com/repos/arvidn/libtorrent/issues/41/events","html_url":"https://github.com/arvidn/libtorrent/issues/41","id":95694508,"number":41,"title":"assert failures on debug build","user":{"login":"bendikro","id":84580,"avatar_url":"https://avatars.githubusercontent.com/u/84580?v=3","gravatar_id":"","url":"https://api.github.com/users/bendikro","html_url":"https://github.com/bendikro","followers_url":"https://api.github.com/users/bendikro/followers","following_url":"https://api.github.com/users/bendikro/following{/other_user}","gists_url":"https://api.github.com/users/bendikro/gists{/gist_id}","starred_url":"https://api.github.com/users/bendikro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bendikro/subscriptions","organizations_url":"https://api.github.com/users/bendikro/orgs","repos_url":"https://api.github.com/users/bendikro/repos","events_url":"https://api.github.com/users/bendikro/events{/privacy}","received_events_url":"https://api.github.com/users/bendikro/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-07-17T16:37:50Z","updated_at":"2015-07-25T05:15:05Z","closed_at":null,"body":"When testing a libtorrent debug build there are some assert failures due to invalid input.\r\n\r\nThese are from libtorrent 1.0.3:\r\n* Assertion failed: (max_connections >= 2 || max_connections == -1), function set_max_connections, file torrent_handle.cpp, line 296.\r\n* Assertion failed: (ec != error::invalid_argument || !m_outgoing), function disconnect, file peer_connection.cpp, line 3553.\r\n* Assertion failed: ((p == -1) == is_finished() || (!m_auto_managed && p == -1) || (m_abort && p == -1)), function set_queue_position, file torrent.cpp, line 6973.\r\n\r\nWould it be possible to *not* have these as asserts? Asserts shouldn't really be failing on invalid input from external callers, but for incorrect logic in the internal code?\r\n\r\nAlso, `torrent_handle::set_max_connections` fails when `max_connections` is 0 or 1, however, `torrent::set_max_connections` uses\r\n```\r\nTORRENT_ASSERT(limit >= -1);\r\nif (limit <= 0) limit = (1<<24)-1;\r\n```\r\nwhich implies that 0 is valid input and is treated as unlimited together with -1.\r\n\r\nWhat happens when running a release build and `torrent_handle::set_max_connections` is called with `max_connections=1`? Will it accept 1 even though the docs says it must be either -1 or >= 2 ?\r\n"},"comment":{"url":"https://api.github.com/repos/arvidn/libtorrent/issues/comments/124800835","html_url":"https://github.com/arvidn/libtorrent/issues/41#issuecomment-124800835","issue_url":"https://api.github.com/repos/arvidn/libtorrent/issues/41","id":124800835,"user":{"login":"arvidn","id":661450,"avatar_url":"https://avatars.githubusercontent.com/u/661450?v=3","gravatar_id":"","url":"https://api.github.com/users/arvidn","html_url":"https://github.com/arvidn","followers_url":"https://api.github.com/users/arvidn/followers","following_url":"https://api.github.com/users/arvidn/following{/other_user}","gists_url":"https://api.github.com/users/arvidn/gists{/gist_id}","starred_url":"https://api.github.com/users/arvidn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arvidn/subscriptions","organizations_url":"https://api.github.com/users/arvidn/orgs","repos_url":"https://api.github.com/users/arvidn/repos","events_url":"https://api.github.com/users/arvidn/events{/privacy}","received_events_url":"https://api.github.com/users/arvidn/received_events","type":"User","site_admin":false},"created_at":"2015-07-25T05:15:05Z","updated_at":"2015-07-25T05:15:05Z","body":"TORRENT_ASSERT_PRECOND() is an assert that preconditions are met when calling this function. It's intended to fail fatally to make it obvious to the programmer that the input is invalid, and break the debugger to make it trivial to see where the call was made and the whole program state.\r\n\r\nThe check is disabled in release builds and (supposed to be) caught by a runtime check that silently ignores the invalid input. I don't see how logging it is preferable. It would make it be ignored by default and may leave bugs go unnoticed.\r\n\r\nNow, obviously it's important that the precondition check matches the documentation. Setting the number of connections to 0 or 1 would probably increase complexity of the API, because it would in effect pause the torrent, meaning there would be multiple distinct states a torrent could be in when paused (and the \"paused\" state would only be one of them)"}}