{"action":"closed","issue":{"url":"https://api.github.com/repos/jthornber/thin-provisioning-tools/issues/29","labels_url":"https://api.github.com/repos/jthornber/thin-provisioning-tools/issues/29/labels{/name}","comments_url":"https://api.github.com/repos/jthornber/thin-provisioning-tools/issues/29/comments","events_url":"https://api.github.com/repos/jthornber/thin-provisioning-tools/issues/29/events","html_url":"https://github.com/jthornber/thin-provisioning-tools/issues/29","id":80892145,"number":29,"title":"btree lower_bound_search::search() doesn't return error if the key is not found","user":{"login":"mingnus","id":8446485,"avatar_url":"https://avatars.githubusercontent.com/u/8446485?v=3","gravatar_id":"","url":"https://api.github.com/users/mingnus","html_url":"https://github.com/mingnus","followers_url":"https://api.github.com/users/mingnus/followers","following_url":"https://api.github.com/users/mingnus/following{/other_user}","gists_url":"https://api.github.com/users/mingnus/gists{/gist_id}","starred_url":"https://api.github.com/users/mingnus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mingnus/subscriptions","organizations_url":"https://api.github.com/users/mingnus/orgs","repos_url":"https://api.github.com/users/mingnus/repos","events_url":"https://api.github.com/users/mingnus/events{/privacy}","received_events_url":"https://api.github.com/users/mingnus/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-26T10:03:54Z","updated_at":"2015-05-26T13:16:02Z","closed_at":"2015-05-26T13:16:02Z","body":"Hi Joe,\r\n\r\nI found a potential bug in btree key search: The function lower_bound_search::search() doesn't check the return value of node_ref::lower_bound(). It will cause error if node_ref::lower_bound() returns -1 when the target key is lower than key_at(0). I think that the code should be modified as following, similar to node_ref::exact_search():\r\n\r\n<pre><code>\r\n--- a/persistent-data/data-structures/btree.tcc\r\n+++ b/persistent-data/data-structures/btree.tcc\r\n@@ -452,7 +452,10 @@ namespace persistent_data {\r\n                template <typename ValueTraits>\r\n                struct lower_bound_search {\r\n                        static boost::optional<unsigned> search(btree_detail::node_ref<ValueTraits> n, uint64_t key) {\r\n-                               return n.lower_bound(key);\r\n+                               int i = n.lower_bound(key);\r\n+                               if (i < 0)\r\n+                                       return boost::optional<unsigned>();\r\n+                               return boost::optional<unsigned>(i);\r\n                        }\r\n                };\r\n</code></pre>\r\n\r\nAlso, in btree_damage_visitor, should the rule of check_parent_key() be this? \r\n<pre><code>if (*key != n.key_at(0))</code></pre>\r\nNow it's\r\n<pre><code>if (*key > n.key_at(0))</code></pre>.\r\n\r\n\r\nThanks"}}