{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/28497","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/28497/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/28497/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/28497/events","html_url":"https://github.com/rust-lang/rust/pull/28497","id":107252775,"number":28497,"title":"Avoid zero-sized leaf allocations in `BTreeMap`","user":{"login":"apasel422","id":8644784,"avatar_url":"https://avatars.githubusercontent.com/u/8644784?v=3","gravatar_id":"","url":"https://api.github.com/users/apasel422","html_url":"https://github.com/apasel422","followers_url":"https://api.github.com/users/apasel422/followers","following_url":"https://api.github.com/users/apasel422/following{/other_user}","gists_url":"https://api.github.com/users/apasel422/gists{/gist_id}","starred_url":"https://api.github.com/users/apasel422/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apasel422/subscriptions","organizations_url":"https://api.github.com/users/apasel422/orgs","repos_url":"https://api.github.com/users/apasel422/repos","events_url":"https://api.github.com/users/apasel422/events{/privacy}","received_events_url":"https://api.github.com/users/apasel422/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"nikomatsakis","id":155238,"avatar_url":"https://avatars.githubusercontent.com/u/155238?v=3","gravatar_id":"","url":"https://api.github.com/users/nikomatsakis","html_url":"https://github.com/nikomatsakis","followers_url":"https://api.github.com/users/nikomatsakis/followers","following_url":"https://api.github.com/users/nikomatsakis/following{/other_user}","gists_url":"https://api.github.com/users/nikomatsakis/gists{/gist_id}","starred_url":"https://api.github.com/users/nikomatsakis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikomatsakis/subscriptions","organizations_url":"https://api.github.com/users/nikomatsakis/orgs","repos_url":"https://api.github.com/users/nikomatsakis/repos","events_url":"https://api.github.com/users/nikomatsakis/events{/privacy}","received_events_url":"https://api.github.com/users/nikomatsakis/received_events","type":"User","site_admin":false},"milestone":null,"comments":8,"created_at":"2015-09-18T18:27:45Z","updated_at":"2015-09-18T20:43:33Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/28497","html_url":"https://github.com/rust-lang/rust/pull/28497","diff_url":"https://github.com/rust-lang/rust/pull/28497.diff","patch_url":"https://github.com/rust-lang/rust/pull/28497.patch"},"body":"When both the key and value types were zero-sized, `BTreeMap` previously\r\ncalled `heap::allocate` with `size == 0` for leaf nodes, which is\r\nundefined behavior, and jemalloc would attempt to read invalid memory,\r\ncrashing the process.\r\n\r\nThis avoids undefined behavior by allocating enough space to store one\r\nedge in leaf nodes that would otherwise have `size == 0`. Although this\r\nuses extra memory, maps with zero-sized key types that have sensible\r\nimplementations of the ordering traits can only contain a single\r\nkey-value pair (and therefore only a single leaf node), and maps with\r\nkey and value types that are both zero-sized have few uses, if any.\r\n\r\nFurthermore, this is a temporary fix that will likely be unnecessary\r\nonce the `BTreeMap` implementation is rewritten to use parent pointers.\r\n\r\nCloses #28493."},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/141563304","html_url":"https://github.com/rust-lang/rust/pull/28497#issuecomment-141563304","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/28497","id":141563304,"user":{"login":"Gankro","id":1136864,"avatar_url":"https://avatars.githubusercontent.com/u/1136864?v=3","gravatar_id":"","url":"https://api.github.com/users/Gankro","html_url":"https://github.com/Gankro","followers_url":"https://api.github.com/users/Gankro/followers","following_url":"https://api.github.com/users/Gankro/following{/other_user}","gists_url":"https://api.github.com/users/Gankro/gists{/gist_id}","starred_url":"https://api.github.com/users/Gankro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gankro/subscriptions","organizations_url":"https://api.github.com/users/Gankro/orgs","repos_url":"https://api.github.com/users/Gankro/repos","events_url":"https://api.github.com/users/Gankro/events{/privacy}","received_events_url":"https://api.github.com/users/Gankro/received_events","type":"User","site_admin":false},"created_at":"2015-09-18T20:43:33Z","updated_at":"2015-09-18T20:43:33Z","body":"@brson this is arguably a regression fix, but this bug has probably been around for ages. I know my originally merged impl didn't have this."}}