{"action":"created","issue":{"url":"https://api.github.com/repos/libgit2/libgit2/issues/3872","repository_url":"https://api.github.com/repos/libgit2/libgit2","labels_url":"https://api.github.com/repos/libgit2/libgit2/issues/3872/labels{/name}","comments_url":"https://api.github.com/repos/libgit2/libgit2/issues/3872/comments","events_url":"https://api.github.com/repos/libgit2/libgit2/issues/3872/events","html_url":"https://github.com/libgit2/libgit2/issues/3872","id":167695166,"number":3872,"title":"inet_pton test in core/posix uses arbitrary hardcoded address families","user":{"login":"mmuman","id":470143,"avatar_url":"https://avatars.githubusercontent.com/u/470143?v=3","gravatar_id":"","url":"https://api.github.com/users/mmuman","html_url":"https://github.com/mmuman","followers_url":"https://api.github.com/users/mmuman/followers","following_url":"https://api.github.com/users/mmuman/following{/other_user}","gists_url":"https://api.github.com/users/mmuman/gists{/gist_id}","starred_url":"https://api.github.com/users/mmuman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmuman/subscriptions","organizations_url":"https://api.github.com/users/mmuman/orgs","repos_url":"https://api.github.com/users/mmuman/repos","events_url":"https://api.github.com/users/mmuman/events{/privacy}","received_events_url":"https://api.github.com/users/mmuman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-26T19:49:03Z","updated_at":"2016-07-26T20:03:25Z","closed_at":null,"body":"In addition to passing NULL as buffers (which asserts Haiku's inet_pton()), the [inet_pton test](https://github.com/libgit2/libgit2/blob/master/tests/core/posix.c#L93) uses arbitrary hardcoded values to test error reporting, which can and actually do collide with some other tested values.\r\nFor example, [AF_INET6](http://cgit.haiku-os.org/haiku/tree/headers/posix/sys/socket.h#n24) is 5 on Haiku.\r\nAnd do we really need to test two of those?\r\n\r\nIf you really want to test with some other value, we could try AF_MAX, although on BSD [it doesn't seem to be always defined (_BSD_VISIBLE)](http://fxr.watson.org/fxr/source/sys/socket.h#L245) and when it is it actually is one of the possible values.\r\nHow about max(AF_INET, AF_INET6)+1 ?\r\n\r\nIt still seems fragile though, as it can still be a valid and actually implemented address family.\r\nAlso note that not all systems actually support (and even define) AF_INET6. MiNT (not the GNU/Linux distro!) comes to mind (but it does define AF_APPLETALK).\r\n\r\nI'd propose some fallbacks from the least known family, something like:\r\n```C\r\n#if defined(AF_DECnet)\r\n#define AF_BAD AF_DECnet\r\n#elif defined(AF_CHAOS)\r\n#define AF_BAD AF_CHAOS\r\n#elif defined(AF_APPLETALK)\r\n#define AF_BAD AF_APPLETALK\r\n#elif defined(AF_MAX)\r\n#define AF_BAD AF_MAX\r\n#else\r\n#define AF_BAD (max(AF_INET, AF_INET6)+1)\r\n#endif\r\n```"},"comment":{"url":"https://api.github.com/repos/libgit2/libgit2/issues/comments/235387477","html_url":"https://github.com/libgit2/libgit2/issues/3872#issuecomment-235387477","issue_url":"https://api.github.com/repos/libgit2/libgit2/issues/3872","id":235387477,"user":{"login":"ethomson","id":1130014,"avatar_url":"https://avatars.githubusercontent.com/u/1130014?v=3","gravatar_id":"","url":"https://api.github.com/users/ethomson","html_url":"https://github.com/ethomson","followers_url":"https://api.github.com/users/ethomson/followers","following_url":"https://api.github.com/users/ethomson/following{/other_user}","gists_url":"https://api.github.com/users/ethomson/gists{/gist_id}","starred_url":"https://api.github.com/users/ethomson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethomson/subscriptions","organizations_url":"https://api.github.com/users/ethomson/orgs","repos_url":"https://api.github.com/users/ethomson/repos","events_url":"https://api.github.com/users/ethomson/events{/privacy}","received_events_url":"https://api.github.com/users/ethomson/received_events","type":"User","site_admin":true},"created_at":"2016-07-26T20:03:25Z","updated_at":"2016-07-26T20:03:25Z","body":"Since `inet_pton` takes an `int` for the address family, I'm relatively sure that it's quite easy to come up with values that are unsupported everywhere, like `INT_MAX-1` or `-1`.\r\n\r\nIn theory, we could also simply `cl__skip` this test on non-Windows, since the goal is to test _our_ `inet_pton` implementation, and if the system implementation is broken then there's not much that we could do about it anyway.  But it is quite nice to know that our implementation matches other platforms.  So it is nice to have it running everywhere."}}
{"actor":{"display_login":"ethomson"}}