{"action":"created","issue":{"url":"https://api.github.com/repos/TooTallNate/ref/issues/46","labels_url":"https://api.github.com/repos/TooTallNate/ref/issues/46/labels{/name}","comments_url":"https://api.github.com/repos/TooTallNate/ref/issues/46/comments","events_url":"https://api.github.com/repos/TooTallNate/ref/issues/46/events","html_url":"https://github.com/TooTallNate/ref/issues/46","id":116401918,"number":46,"title":"Void** deref -> Void* Sometimes provides Buffer of Length 0","user":{"login":"sedouard","id":3053263,"avatar_url":"https://avatars.githubusercontent.com/u/3053263?v=3","gravatar_id":"","url":"https://api.github.com/users/sedouard","html_url":"https://github.com/sedouard","followers_url":"https://api.github.com/users/sedouard/followers","following_url":"https://api.github.com/users/sedouard/following{/other_user}","gists_url":"https://api.github.com/users/sedouard/gists{/gist_id}","starred_url":"https://api.github.com/users/sedouard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sedouard/subscriptions","organizations_url":"https://api.github.com/users/sedouard/orgs","repos_url":"https://api.github.com/users/sedouard/repos","events_url":"https://api.github.com/users/sedouard/events{/privacy}","received_events_url":"https://api.github.com/users/sedouard/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-11-11T19:14:30Z","updated_at":"2015-11-11T22:49:46Z","closed_at":null,"body":"Consider this tiny repro:\r\n\r\n```js\r\nvar ref = require('ref');\r\n\r\nvar types = {\r\n  HKEY: ref.refType(ref.types.void)\r\n}\r\n\r\ntypes.PHKEY = ref.refType(types.HKEY);\r\n\r\nvar pHKey = ref.alloc(types.PHKEY);\r\n\r\nconsole.log('pHKey length: ' + pHKey.length);\r\nconsole.log('hKey length: ' + pHKey.deref().length);\r\n```\r\n\r\nThis error doesn't seem OS specific. Run this repeatedly and see:\r\n\r\n```\r\n>node ./ref-test.js\r\npHKey length: 8\r\nhKey length: 8\r\n>node ./ref-test.js\r\npHKey length: 8\r\nhKey length: 8\r\n\r\n>node ./ref-test.js\r\npHKey length: 8\r\nhKey length: 8\r\n\r\n>node ./ref-test.js\r\npHKey length: 8\r\nhKey length: 8\r\n\r\n>node ./ref-test.js\r\npHKey length: 8\r\nhKey length: 8\r\n\r\n>node ./ref-test.js\r\npHKey length: 8\r\nhKey length: 0 << I would expect void* to still have POINTER_SIZE length\r\n```"},"comment":{"url":"https://api.github.com/repos/TooTallNate/ref/issues/comments/155934028","html_url":"https://github.com/TooTallNate/ref/issues/46#issuecomment-155934028","issue_url":"https://api.github.com/repos/TooTallNate/ref/issues/46","id":155934028,"user":{"login":"TooTallNate","id":71256,"avatar_url":"https://avatars.githubusercontent.com/u/71256?v=3","gravatar_id":"","url":"https://api.github.com/users/TooTallNate","html_url":"https://github.com/TooTallNate","followers_url":"https://api.github.com/users/TooTallNate/followers","following_url":"https://api.github.com/users/TooTallNate/following{/other_user}","gists_url":"https://api.github.com/users/TooTallNate/gists{/gist_id}","starred_url":"https://api.github.com/users/TooTallNate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TooTallNate/subscriptions","organizations_url":"https://api.github.com/users/TooTallNate/orgs","repos_url":"https://api.github.com/users/TooTallNate/repos","events_url":"https://api.github.com/users/TooTallNate/events{/privacy}","received_events_url":"https://api.github.com/users/TooTallNate/received_events","type":"User","site_admin":false},"created_at":"2015-11-11T22:49:46Z","updated_at":"2015-11-11T22:49:46Z","body":"nvm, happens on v4.2.1 as well.\r\n\r\nSo this is actually expected behavior: what's happening is that `pHKey` buffer is allocated with uninitialized memory, meaning that it could contain any random bits of data. Sometimes that data is all 0s, which when dereferenced via `pHKey.deref()` causes a NULL pointer to be read, which ref forces to 0 byte length.\r\n\r\nClosing as working as expected.\r\n\r\nIs there a bit of C code that you're attempting to convert to ffi? I can help with that if you have a C snippet to show."}}